JavaScript has a strict mode with tighter rules: some words are reserved, with is forbidden, deleting a plain variable is an error. ES modules and class bodies are always strict; older scripts are strict only with a "use strict" line. alwaysStrict makes TypeScript parse every file as strict and report what strict mode forbids, such as package used as a variable name (TS1212).
It is part of strict. Its other job, writing "use strict" into output files, does not apply with noEmit. TypeScript 6.0 treats all code as strict and deprecates turning it off.
At a glance
| Write | Leave it to strict; write "alwaysStrict": false only to turn this one check back off |
|---|---|
| On the command line | --alwaysStrict |
| Type | boolean |
| Default in TypeScript 5.9 | false (on when strict is on) |
| Default from TypeScript 6.0 | true: setting it to false is deprecated (TypeScript 6.0) |
| TypeScript's description | Ensure 'use strict' is always emitted. |
The description is quoted from TypeScript's own option list (Apache-2.0); see the notices.
Examples
var package = "jswt";error TS1212: Identifier expected. 'package' is a reserved word in strict mode.
console.log(package);error TS1212: Identifier expected. 'package' is a reserved word in strict mode.jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": false,
"target": "es2022",
"module": "esnext",
"types": [],
"moduleResolution": "bundler",
"alwaysStrict": true
},
"include": [
"*.js"
]
} var package = "jswt";
console.log(package);jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": false,
"target": "es2022",
"module": "esnext",
"types": [],
"moduleResolution": "bundler"
},
"include": [
"*.js"
]
} Which files it affects
Only scripts: files that are not modules, such as classic <script> files in a browser project. The examples use one (no import or export, module: "esnext", no "type" in package.json). ES modules are strict whether or not the option is on, and in TypeScript 5.9 CommonJS files checked under module: "nodenext" are treated as strict too.
Under TypeScript 6.0 and 7.0
Every example on this page also runs under TypeScript 6.0.3 and 7.0.2 when this site is built. One of them reports something different from 5.9.3, the version the page describes; the ✗ on its badge links to its entry below.
Every file is parsed in strict mode
The pattern: A word that strict mode reserves (package, private, static, public) used as a variable name in a project with "strict": false.
Why: 6.0 deprecates alwaysStrict: false: per the release notes, all code is now assumed to be in JavaScript strict mode, whatever strict says. So the reserved word is a syntax error (TS1212) in 6.0 and 7.0, where 5.9 accepted it with strict off. Source: TypeScript 6.0 release notes: Deprecated: --alwaysStrict false.
alwaysStrict off: the script is parsed in sloppy mode main.js
- TypeScript 5.9.3
No errors.
- TypeScript 6.0.3differs from 5.9.3
main.js(1,5): error TS1212: Identifier expected. 'package' is a reserved word in strict mode. main.js(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode.
- TypeScript 7.0.2differs from 5.9.3
main.js(1,5): error TS1212: Identifier expected. 'package' is a reserved word in strict mode. main.js(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode.
What works in every version: Rename the variable (pkg for package). A module file (one with import or export) is strict in every version anyway.
Gotchas
- Scripts that rely on sloppy-mode behavior (assigning to an undeclared variable to create a global, for example) break when they run as modules; this option shows you those spots before you switch.
Sources
- TSConfig Reference: alwaysStrict · TypeScript
- TypeScript 2.1 release notes · TypeScript handbook
- TypeScript 6.0 release notes · TypeScript handbook
Last reviewed 20 October 2026.