TypeScript Syntax

import equals — CommonJS-style module import

TypeScript import equals can bind the export of a CommonJS-shaped module. In the CommonJS fixture it emits a require call. An internal namespace alias form also exists. Module settings and runtime loading rules matter; do not assume this is interchangeable with every ECMAScript import form. Multi-file example: save each labeled file separately in one directory and compile the project. Observed output: '5'. Local verification: TypeScript 5.8.3, strict mode, ES2022, CommonJS, Node.js 22.16.0. Disposable library declarations are enabled for the fixture suite.

Formal Syntax & Structure

typescript syntaxtypescript
import name = require("./module");

Working Example

Example Snippettypescript
// File: catalog.tsconst catalog = { count: 5 };export = catalog;
// File: main.tsimport catalog = require("./catalog");console.log(catalog.count);
TypeScript Reference