Triple-slash directives help TypeScript find extra files or give special instructions before compiling. They tell the compiler about dependencies or settings.
Triple-slash directives in Typescript
/// <directiveName attribute="value" />Triple-slash directives start with three slashes and are single-line comments.
They must be at the very top of the file before any code.
types.d.ts./// <reference path="./types.d.ts" />node package, useful when working with Node.js./// <reference types="node" />/// <amd-module name="myModule" />This program uses a triple-slash directive to include type definitions from shapes.d.ts. It then defines a function that uses the Circle type and prints a message.
/// <reference path="./shapes.d.ts" /> function drawCircle(radius: number) { const circle: Circle = { radius }; console.log(`Drawing circle with radius ${circle.radius}`); } drawCircle(5);
Triple-slash directives are only for the TypeScript compiler and do not affect runtime JavaScript.
They must be placed at the top of the file before any other statements or imports.
Using /// <reference types="..." /> is common to include types from npm packages.
Triple-slash directives give instructions to the TypeScript compiler using special comments.
They help include type information and manage dependencies between files.
Always place them at the very top of your TypeScript files.