You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In using frozen objects to create enums, it seems the literal value is not inferred to the type of that object's property.
In the following example, when using the $Values utility we get a union of the values, as expected ('THING' | 'THING_TWO'), but when using typeof to get the type of one of these properties, we get a type of string. I'd expect to get the string literal type instead.
const ENUM = Object.freeze({
THING: 'THING',
THING_TWO: 'THING_TWO',
});
const notAThing: typeof ENUM.THING = 'NOT_A_THING' // no error
const isAThing: $Values<typeof ENUM> = 'IS_A_THING' // Cannot assign `'IS_A_THING'` to `isAThing` because string [1] is incompatible with enum [2].
In using frozen objects to create enums, it seems the literal value is not inferred to the type of that object's property.
In the following example, when using the $Values utility we get a union of the values, as expected (
'THING' | 'THING_TWO'
), but when usingtypeof
to get the type of one of these properties, we get a type ofstring
. I'd expect to get the string literal type instead.Try Flow
Of course, typing each property individually works, but I'd expect
Object.freeze()
to produce the same output. Is there another way around this?The text was updated successfully, but these errors were encountered: