Skip to content
Latchkey

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

  1. Give the property a default, or assign it in the constructor
ts
class User {
  name = ""
}

Use the definite assignment assertion

  1. 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

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card