When set to true, TypeScript will raise an error when a class property was declared but not set in the constructor.
ts
// @errors: 2564
class UserAccount {
name: string;
accountType = "user";
email: string;
address: string | undefined;
constructor(name: string) {
this.name = name;
// Note that this.email is not set
}
}// @errors: 2564
class UserAccount {
name: string;
accountType = "user";
email: 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.