Property '...' has no initializer and is not definitely assigned in the constructor
If none of this works, you can try it
"angularCompilerOptions": {
....
"strictPropertyInitialization": false,
...
}
This is caused by TypeScript's Strict Class Initialization.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#strict-class-initialization
To resolve this issue you must either declare that the type can be both Foo|undefined, or utilize the '!' symbol to indicate definite assignment as per the above documentation:
Case 1:
@Component({...})
export class Component {
@Input() myInput: string|undefined;
}
We indicate that the type may be either a string or undefined.
Case 2:
@Component({...})
export class Component {
@Input() myInput!: string;
}
In this case we utilize the ! symbol to indicate that we are aware that myInput
is not initialized in the constructor and we will handle it elsewhere.
Alternate Solution
If you do not care about strict class initialization, you can disable the feature completely in your tsconfig.json
by adding a flag to your compiler options
{
"compilerOptions": {
"strictPropertyInitialization": false
}
}
Note: You will have to restart the TypeScript server for the compilerOptions to be reapplied. The easiest way to achieve this is to simply restart your IDE.