Skip to content

Triple Slash Directive

In one line

/// directives are single-line comments that instruct the TypeScript compiler — used for type references and path aliases.

In simple words

Triple slash directives are special comments starting with /// that give instructions to the TypeScript compiler. They must appear at the top of the file before any code.

Common directives:

  1. /// <reference path="..." /> — include a type declaration file
  2. /// <reference types="..." /> — reference a @types package
  3. /// <reference lib="..." /> — include a built-in lib (es2020, dom)
  4. /// <amd-module name="..." /> — name an AMD module

In modern TypeScript, most of these are replaced by tsconfig.json settings (types, lib, paths). Triple slash is mainly needed in .d.ts files or for legacy build systems.

Example

typescript
/// <reference path="./types/custom.d.ts" />
/// <reference types="node" />
/// <reference lib="es2020" />

// Now we can use Node.js types and ES2020 features
const buf: Buffer = Buffer.from("hello");
const result: bigint = 1n + 2n;

// Modern alternative: tsconfig.json
// {
//   "compilerOptions": {
//     "types": ["node"],
//     "lib": ["es2020", "dom"]
//   }
// }

/// directives tell the compiler to include type files, @types packages, or built-in libs. Modern projects use tsconfig.json instead.

Common confusions

  • Confused with: regular comment

    The difference: A regular comment (// or /* */) is ignored by the compiler. A triple slash directive (///) is parsed by the compiler as an instruction. The triple slash must be at the top of the file and followed by an XML-like tag.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary