TS2564: Property has no initializer - in CI
With strictPropertyInitialization on, a class property is neither initialized nor definitely assigned in the constructor.
What this error means
Type-checking fails with TS2564 naming the uninitialized property on a class.
tsc
src/user.ts(2,3): error TS2564: Property 'name' has no initializer and is not definitely assigned in the constructor.Common causes
How to fix it
Initialize or assign in the constructor
- Give the property a default, or assign it in the constructor
ts
class User {
name = ""
}Use the definite assignment assertion
- When a framework guarantees assignment, mark it with ! to opt out
ts
class User {
name!: string
}How to prevent it
- Initialize class fields or use the definite-assignment ! only where a framework truly sets them.
Frequently asked questions
What causes "TS2564 no initializer"?
Type-checking fails with TS2564 naming the uninitialized property on a class.
How do I fix TS2564 no initializer?
Initialize or assign in the constructor
Related guides
TS2515: Non-abstract class does not implement abstract member - in CIFix "error TS2515: Non-abstract class 'X' does not implement inherited abstract member 'y'" when tsc runs in…
TS2412: exactOptionalPropertyTypes property assignment - in CIFix "error TS2412: Type 'undefined' is not assignable ... with exactOptionalPropertyTypes: true" when assigni…
TS2322: Type is not assignable - in CIFix "error TS2322: Type 'X' is not assignable to type 'Y'" when tsc runs in CI - a genuine type mismatch on a…