TypeScript Concepts

Ambient declarations — describing existing values

An ambient declaration supplies static information about a value or module expected to exist elsewhere. It provides no implementation. A wrong declaration can make a call type-check while failing at runtime. In the example the JavaScript file really implements the exported function; the accompanying declaration describes it. Compile with allowJs off and copy the JavaScript file into the output folder, or use the included verified fixture. Split the listing into the indicated files before compiling. Observed output: '8'. Local example verified with TypeScript 5.8.3, strict checking, ES2022/CommonJS and Node.js 22.16.0; declarations enabled.

Formal Syntax & Structure

typescript syntaxtypescript
declare function existing(value: number): number;

Working Example

Example Snippettypescript
// File: main.tsimport { double } from "./math";console.log(double(4));
// File: math.d.tsexport declare function double(value: number): number;
// File: math.jsexports.double = value => value * 2;
TypeScript Reference