CodeBlanks Logo Icon CodeBlanks

Triple-slash directive

Learn triple-slash directives.

What is a triple-slash directive?

A triple-slash directive is a single-line comment that gives special instructions to the compiler. It starts with /// and is processed differently from a normal // comment. Its most common use is /// <reference path="..." /> to reference another .d.ts file.

/// <reference path="./types.d.ts" />

Other reference directives

The reference directive has different attributes. The types attribute specifies which @types packages to include. The lib attribute specifies which built-in lib files to include.

/// <reference types="node" />
/// <reference lib="es2020" />

Practice Reference the math.d.ts file

Use /// <reference path="./math.d.ts" /> to reference the math.d.ts file. Then print "başvuruldu" with console.log.

Starter code

index.ts
// math.d.ts dosyasına triple-slash yönergesi ile başvur

console.log("başvuruldu");

Sample solution

index.ts
/// <reference path="./math.d.ts" />
console.log("başvuruldu");

Expected output

başvuruldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How many slashes must a triple-slash directive start with?

  • Four slashes (////)
  • Single slash (/)
  • Three slashes (///) Correct answer
  • Two slashes (//)

Explanation: A triple-slash directive starts with exactly three slashes (///); two slashes is a normal comment.

2 reference directive tag

Question
/// <____ path="./types.d.ts" />
Answer
/// <reference path="./types.d.ts" />

Explanation: The tag name of the triple-slash reference directive is `reference`; it takes path, types or lib attributes.

3 Triple-slash directives

Term Meaning
path File path attribute
types Type package attribute
lib Built-in library attribute
/// Directive prefix

All lessons in Intermediate