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

Created on 29 Sep 2020  路  4Comments  路  Source: JSMonk/hegel

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

bug

Most helpful comment

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.

All 4 comments

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.

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 it's flow's syntax...

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.

Was this page helpful?
0 / 5 - 0 ratings