hegel icon indicating copy to clipboard operation
hegel copied to clipboard

got 'Property is always "undefined"' when it's not always "undefined"

Open thecotne opened this issue 5 years ago • 5 comments

type AA = {
    a:? number,
    b:? number,
    c:? string,
}

const a: AA = {};

if(a.a !== undefined && a.b !== undefined && a.c !== undefined) {// error: Property is always "undefined"

}

try

thecotne avatar Sep 29 '20 15:09 thecotne

Found a temporary solution. It doesn't fix the bug though. You can wrap the first condition in parentheses.

type AA = {
    a:? number,
    b:? number,
    c:? string,
}

const a: AA = {};

if((a.a !== undefined && a.b !== undefined) && a.c !== undefined) {
    
}

This is better than ignoring bug with // @hegel-issue comment.

Try.

artanik avatar Sep 29 '20 17:09 artanik

That's interesting (and sorry, off topic), the syntax c:? string, doesn't seem to be compatible with TS (not sure if that's a goal). In TS it is c?: string, (example).

trusktr avatar Nov 08 '20 21:11 trusktr

@trusktr it's flow's syntax...

thecotne avatar Nov 08 '20 21:11 thecotne

Do you guys like Flow better than TypeScript? (Just curious)

TypeScript seems to have higher usage, so if Hegel syntax is more aligned with TS, then easier for people to migrate to and adopt Hegel.

trusktr avatar Nov 11 '20 21:11 trusktr

Oh, just fixed it, so it will work in the new Hegel version.

JSMonk avatar Jan 30 '21 21:01 JSMonk