TypeScript Compiler Options
useDefineForClassFields — TypeScript compiler option
Chooses standard class-field definition semantics rather than legacy assignment semantics. A definition creates an own data property; an assignment can invoke an inherited setter. This can change runtime behavior during migrations even when type checking succeeds. Downlevel output uses property definition helpers or Object.defineProperty as appropriate. Default: True at ES2022 and above; false below ES2022 in 5.8.3. Create the named files in a clean local project and run tsc -p tsconfig.json. Expected emitted files: dist/example.js. Run node dist/example.js; expected stdout: 'true'. Tested with TypeScript 5.8.3 and Node.js 22.16.0; local project example, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "useDefineForClassFields": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| useDefineForClassFields | boolean | Set in compilerOptions; True at ES2022 and above; false below ES2022 in 5.8.3. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "outDir": "dist", "useDefineForClassFields": true }, "files": [ "example.ts" ]}// File: example.tsclass Base {}Object.defineProperty(Base.prototype, "score", { set(value: number) { console.log("setter", value); } });class Child extends Base { score = 7; }const child = new Child();console.log(Object.prototype.hasOwnProperty.call(child, "score"));