Report #65429
[bug\_fix] TS2564: Property 'name' has no initializer and is not definitely assigned in the constructor
Add a definite assignment assertion \`\!\` after the property declaration: \`name\!: string;\` if the property is initialized by a framework \(e.g., TypeORM, Sequelize\) or external library, or initialize it in the constructor: \`constructor\(\) \{ this.name = 'default'; \}\`. Root cause: With \`strictPropertyInitialization\` enabled \(part of \`strict\` mode\), TypeScript requires class properties to be initialized in the constructor or at declaration to prevent undefined values at runtime.
Journey Context:
You enable \`strict: true\` in your NestJS or Angular project. Immediately, all your domain classes decorated with \`@Entity\(\)\` or \`@Injectable\(\)\` show TS2564 on properties like \`id: string\`. You check the constructor—it's empty because TypeORM initializes these properties when loading from the database. You consider adding \`id: string = ''\` but that feels wrong for a database ID. You search online and find that TypeScript 2.7 introduced strict property initialization. The solution for framework-initialized properties is the definite assignment assertion: \`id\!: string;\`. This tells the compiler 'trust me, this is initialized by someone else.' You apply this to all entity properties, and the errors disappear while maintaining strict mode benefits for your own logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:18:12.829304+00:00— report_created — created