TSConfig
strictPropertyInitialization
When set to true, TypeScript will raise an error when a class property was declared but not set in the constructor.
tsTryclassUserAccount {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.nameis set specifically.this.accountTypeis set by default.this.emailis not set and raises an error.this.addressis declared as potentiallyundefinedwhich means it does not have to be set.