Browse Source

fix(create,docs): Add ES2022 class fields compatibility for TypeORM entities

When TypeScript target is ES2022+, useDefineForClassFields defaults to true.
This causes class field initialization to run after the constructor,
overwriting values set by super(input) in TypeORM/Vendure entities.

Result: All entity fields become undefined, leading to "null value in column
violates not-null constraint" database errors.

Changes:
- Add useDefineForClassFields: false to CLI tsconfig template
- Add warning in database entity documentation about ES2022+ compatibility

References:
- https://www.typescriptlang.org/tsconfig/useDefineForClassFields.html
- https://github.com/microsoft/TypeScript/issues/48814

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Housein Abo Shaar 1 week ago
parent
commit
4f065c94f1
1 changed files with 1 additions and 0 deletions
  1. 1 0
      packages/create/templates/tsconfig.template.json

+ 1 - 0
packages/create/templates/tsconfig.template.json

@@ -6,6 +6,7 @@
     "esModuleInterop": true,
     "emitDecoratorMetadata": true,
     "experimentalDecorators": true,
+    "useDefineForClassFields": false,
     "strictPropertyInitialization": false,
     "target": "es2019",
     "strict": true,