[[strictPropertyInitialization]]を使うと以下のようなコードはエラーになる。
```ts
class Human {
id: number;
// Property 'id' has no initializer and is not definitely assigned in the constructor. (tsserver 2564)
name: string;
}
```
これは[[プロパティ (TypeScript)|プロパティ]]が初期化されていないからであり、[[コンストラクタ (TypeScript)|コンストラクタ]]で初期化すると解消される。
```ts
class Human {
id: number;
name: string;
constructor(id: number, name: string) {
this.id = id;
this.name = name;
}
}
```
しかし、[[コンストラクタ (TypeScript)|コンストラクタ]]の中で呼び出した関数や[[メソッド (TypeScript)|メソッド]]の内部で初期化しても、それは解析されない。つまりエラーとなってしまう。
```ts
class Human {
id: number;
// Property 'id' has no initializer and is not definitely assigned in the constructor. (tsserver 2564)
name: string;
constructor(id: number, name: string) {
this.init(id, name);
}
init(id: number, name: string) {
// ここで初期化しているのにinitメソッドは解析対象外
this.id = id;
this.name = name;
}
}
```