TSConfig
strictPropertyInitialization
When set to true, TypeScript will raise an error when a class property was declared but not set in the constructor.
tsTry
classUserAccount {name : string;accountType = "user";Property 'email' has no initializer and is not definitely assigned in the constructor.2564Property 'email' has no initializer and is not definitely assigned in the constructor.: string; address : string | undefined;constructor(name : string) {this.name =name ;// Note that this.email is not set}}
In the above case:
this.name
is set specifically.this.accountType
is set by default.this.email
is not set and raises an error.this.address
is declared as potentiallyundefined
which means it does not have to be set.