TypeScript Compiler Options
allowJs — TypeScript compiler option
Allows JavaScript input in mixed projects and type inference from JavaScript and JSDoc. With output paths configured, JavaScript can be emitted or used to generate declarations. Body diagnostics depend on checkJs or directives. Default (5.8.3): false unless checkJs is enabled. Create the labeled files in an isolated project and run tsc -p tsconfig.json. No diagnostics; output: dist/main.js, dist/legacy.js. Run node dist/main.js; expected stdout: '6'. Local project fixture, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "allowJs": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| allowJs | boolean | Set in compilerOptions; default: false unless checkJs is enabled. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "noEmit": false, "allowJs": true, "outDir": "dist" }, "files": [ "main.ts" ]}// File: main.tsimport { twice } from "./legacy";console.log(twice(3));// File: legacy.js/** @param {number} n */export function twice(n) { return n * 2; }