TypeScript Compiler Options

esModuleInterop — TypeScript compiler option

Changes checking and CommonJS interoperability emission, including wrapper helpers for default and namespace imports. Enables synthetic defaults unless explicitly overridden. Match the actual loader. Default (5.8.3): mode-dependent; false in tested CommonJS configuration. Create the labeled files in an isolated project and run tsc -p tsconfig.json. No diagnostics; output: main.js, dep.js. Run node main.js; expected stdout: '8'. Local project fixture, not a single-file editor.

Formal Syntax & Structure

typescript syntaxtypescript
{  "compilerOptions": {    "esModuleInterop": true  }}

Parameters & Attributes

NameTypeDescription
esModuleInteropbooleanSet in compilerOptions; default: mode-dependent; false in tested CommonJS configuration.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmitOnError": true,    "noEmit": false,    "esModuleInterop": true  },  "files": [    "main.ts",    "dep.ts"  ]}// File: main.tsimport double from "./dep";console.log(double(4));// File: dep.tsfunction double(n: number) { return n * 2; }export = double;
TypeScript Reference