-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught uninitialized class member with Symbol key #40617
Comments
Actually, it looks like this is true of any computed property declaration 😦 |
function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
setParent(reference.expression, reference);
setParent(reference, constructor);
reference.flowNode = constructor.returnFlowNode;
const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType));
return !(getFalsyFlags(flowType) & TypeFlags.Undefined);
} I think const Foo = Symbol()
class WithFoo {
[Foo]: any[];
["prop"]: any[];
constructor() {
this[Foo] = []; ??
this["prop"] = []; // Works
}
} @andrewbranch What do you think? |
@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 |
I don’t know though, it seems like issuing the error when there is no constructor would be better than nothing... |
TypeScript Version: 4.1.0-dev.20200917
Search Terms:
symbol class member uninitialized
Code
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 propertyFoo
.Actual behavior:
No such error is thrown.
Playground Link:
here
The text was updated successfully, but these errors were encountered: