TypeScript Compiler Options
moduleDetection — TypeScript compiler option
Determines script versus module scope. Force makes non-declaration files modules; legacy looks for imports and exports; auto additionally considers package type in Node modes and automatic JSX runtime. Script globals can collide. Default (5.8.3): auto. Create the labeled files in an isolated local project and run tsc -p tsconfig.json. Expected: no diagnostics; emitted files: none. Local multi-file fixture, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "moduleDetection": "force" }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| moduleDetection | auto | legacy | force | Set in compilerOptions; default: auto. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "noEmit": true, "moduleDetection": "force" }, "files": [ "main.ts", "other.ts" ]}// File: main.tsconst count = 1;// File: other.tsconst count = 2;