TypeScript Compiler Options
alwaysStrict — TypeScript compiler option
Parses source in ECMAScript strict mode and adds a strict-mode directive where necessary for emitted scripts. This is different from purely static flags. Modules already have strict-mode semantics, so use a script to observe the difference. It does not enable all the other strict-family checks. Default: inherits the effective strict setting (false when strict is omitted in 5.8.3). The example compares emitted strict-mode prologues with the flag explicitly false and true. Observed corrected runtime output: 'true'. 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
typescript syntaxtypescript
{ "compilerOptions": { "alwaysStrict": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| alwaysStrict | boolean | Set explicitly to true or false; omission uses the default described above. |
Working Example
Example Snippettypescript
// File: tsconfig.json (JSON; omit this file-label comment){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "types": [], "noEmitOnError": true, "strict": false, "alwaysStrict": true }, "files": [ "example.ts" ]}// File: example.tsfunction receiver() { return this === undefined; }console.log(receiver());