Advertisement
Advanced TypeScript, Declaration Files

What is 'triple-slash directive' syntax and when is it still necessary in modern TypeScript?

Short answer

Triple-slash directives like `/// ` at the top of a file are an older mechanism for explicitly pulling in ambient type declarations, mostly superseded by automatic node_modules/@types resolution — still occasionally needed in standalone .d.ts files or when writing global scripts…

Save TypeScript mock interview
Advertisement
AModel answer
Triple-slash directives like `/// <reference types="node" />` at the top of a file are an older mechanism for explicitly pulling in ambient type declarations, mostly superseded by automatic node_modules/@types resolution — still occasionally needed in standalone .d.ts files or when writing global scripts outside a normal module graph.
/// <reference types="node" />
declare const process: NodeJS.Process; // relies on @types/node's ambient types
Real-world example
Explicitly including Node.js global types in a script-mode .d.ts file that isn't part of the normal module resolution graph.
Likely follow-ups
  • Why is this directive rarely needed for regular application code that imports @types packages normally?
Related topics