TS2564

error TS2564: Property ‘key’ has no initializer and is not definitely assigned in the constructor.

Info: This error occurs with TypeScript 2.7 in “strict” mode because TypeScript 2.7 introduced a new flag called --strictPropertyInitialization, which tells the compiler to check that each instance property of a class gets initialized in the constructor body, or by a property initializer. See Strict Class Initialization.

Bad Code ❌

1
2
3
4
class CipherKey {
key: Uint8Array;
constructor() {}
}

Fixed Code ✔️

1
2
3
4
5
6
7
class CipherKey {
key: Uint8Array;

constructor() {
this.key = new Uint8Array([]);
}
}