Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 03182cd

Browse files
authored
Merge branch 'master' into 2.1ReleaseNotes
2 parents b91dd42 + 20d7da3 commit 03182cd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pages/Triple-Slash Directives.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ It is an error for a file to have a triple-slash reference to itself.
3737

3838
If the compiler flag `--noResolve` is specified, triple-slash references are ignored; they neither result in adding new files, nor change the order of the files provided.
3939

40+
## `/// <reference types="..." />`
41+
42+
Similar to a `/// <reference path="..." />` directive, this directive serves as a declaration of *dependency*;
43+
a `/// <reference types="..." />`, however, declares a dependency on an `@types` package.
44+
45+
Including `/// <reference types="node" />` in a declaration file declares that this file uses names declared in `@types/node/index.d.ts`;
46+
and thus, this package needs to be included in the compilation along with the declaration file.
47+
48+
The process of resolving these `@types` package names are similar to process of resolving module names in an `import` statement.
49+
An easy way to think of triple-slash-reference-types directives as an `import` for declaration packages.
50+
51+
Use these directives only when you're authoring a `d.ts` file by hand.
52+
53+
For declaration files generated during compilation, the compiler will automatically add `/// <reference types="..." />` for you;
54+
A `/// <reference types="..." />` in a generated declaration file is added *if and only if* the resulting file uses any declarations from the referenced `@types` package.
55+
56+
For declaring a dependency on an `@types` package in a `.ts` file, use `--types` on the command line or in your `tsconfig.json` instead.
57+
See [using `@types`, `typeRoots` and `types` in `tsconfig.json` files](./tsconfig.json.md#types-typeroots-and-types) for more details.
58+
4059
## `/// <reference no-default-lib="true"/>`
4160

4261
This directive marks a file as a *default library*.

0 commit comments

Comments
 (0)