-
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
StrictPropertyInitialization does not understand calls to helpers #21132
Comments
The compiler does not analyze all calls from the constructor. for these, use definite assignment operator |
See also long discussion of how this would be an expected effect #8476 |
I understand that inheritance could make tracking calls from the constructor tricky if public methods were called. export class Test {
private _foo: string;
constructor() {
this._init(); //<- follow this chain
this.myMethod();//<- don't follow this chain
}
private _init(override?: string) {
this._foo = override || 'test';
}
public myMethod() {
this._foo = 'bar'; // This isn't used to track strict property init
}
public resetState() {
this._init('reset');
}
} |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.0-dev.20180110
Code
https://github.com/berickson1/Playground/blob/master/strictPropertyInitError.ts
Expected behavior:
Code compiles with strict flags on
Actual behavior:
strictPropertyInitError.ts(4,13): error TS2564: Property '_foo' has no initializer and is not definitely assigned in the constructor.
The text was updated successfully, but these errors were encountered: