exactOptionalPropertyTypes — TypeScript compiler option
Distinguishes an absent optional property from a present property explicitly set to undefined. With this flag a property written p?: string does not accept an explicit undefined unless it is part of the value type. Reading a possibly absent property still yields string | undefined. Requires strictNullChecks. Default: false in 5.8.3, including with strict enabled. With the enforcing setting, the corrected example compiles; the comparison fixture triggers TS2375. Disabling this particular check accepts the comparison fixture. Observed corrected runtime output: 'false'. Use two separate files as labeled, then run tsc -p tsconfig.json and node example.js in an isolated directory. Tested with TypeScript 5.8.3 and Node.js 22.16.0; not a single-file live editor example.
Formal Syntax & Structure
{ "compilerOptions": { "exactOptionalPropertyTypes": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| exactOptionalPropertyTypes | boolean | Set explicitly to true or false; omission uses the default described above. |
Working Example
// File: tsconfig.json (JSON; omit this file-label comment){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "types": [], "noEmitOnError": true, "strict": true, "exactOptionalPropertyTypes": true }, "files": [ "example.ts" ]}// File: example.tstype Settings = { label?: string };const settings: Settings = {};console.log("label" in settings);