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
{{ message }}
Repository navigation
Uncaught uninitialized class member with Symbol key #40617
constFoo=Symbol()classWithFoo{[Foo]: any[];// this shouldn't be allowed without an initialization in a constructorFoo: any[];// compare with this, which errors as expected}console.log(newWithFoo()[Foo].length)// uncaught uninitialized symbol member, oops
Expected behavior:
An error like Property 'Foo' has no initializer and is not definitely assigned in the constructor should also be emitted for the symbolic property Foo.
I think isPropertyInitializedInConstructor can be extended to use both ElementAccessExpression and PropertyAccessExpression, however, I'm not sure that getFlowTypeOfReference can resolve the right type for ElementAccessExpressions with Identifiers.
Oleksandr Tarasiuk (@a-tarasyuk) you’re right, that would require #36230. Maybe the current behavior is intentional, then, as we’re looking at a choice between always¹ issuing the uninitialized error or never issuing it. 😕
¹ “always,” unless the initialization is on the class field itself, or the error is suppressed with !. These are pretty good as workarounds go, but I’m not sure they’re good enough to merit this change.
Activity
andrewbranch commentedon Sep 18, 2020
Actually, it looks like this is true of any computed property declaration 😦
https://www.typescriptlang.org/play?ts=4.0.2#code/MYGwhgzhAEDqCWAXAFgMQPbugbwFDWgG0AiAI3GWIF0AuaMAOwE9CqBufaDdOxl93AF9cuYOgYR0IAKYA6EOgDmACgbSA7nCRpMygJSzyYZPOkNFKPdAD016JgAOEIA
a-tarasyuk commentedon Nov 9, 2020
isPropertyInitializedInConstructordoesn't supportElementAccessExpression, onlyPropertyAccessExpression.I think
isPropertyInitializedInConstructorcan be extended to use bothElementAccessExpressionandPropertyAccessExpression, however, I'm not sure thatgetFlowTypeOfReferencecan resolve the right type forElementAccessExpressions withIdentifiers.Andrew Branch (@andrewbranch) What do you think?
andrewbranch commentedon Nov 13, 2020
Oleksandr Tarasiuk (@a-tarasyuk) you’re right, that would require #36230. Maybe the current behavior is intentional, then, as we’re looking at a choice between always¹ issuing the uninitialized error or never issuing it. 😕
¹ “always,” unless the initialization is on the class field itself, or the error is suppressed with
!. These are pretty good as workarounds go, but I’m not sure they’re good enough to merit this change.andrewbranch commentedon Nov 13, 2020
I don’t know though, it seems like issuing the error when there is no constructor would be better than nothing...