You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/documentation/copy/en/reference/Triple-Slash Directives.md
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ Triple-slash directives are **only** valid at the top of their containing file.
13
13
A triple-slash directive can only be preceded by single or multi-line comments, including other triple-slash directives.
14
14
If they are encountered following a statement or a declaration they are treated as regular single-line comments, and hold no special meaning.
15
15
16
+
As of TypeScript 5.5, the compiler does not generate reference directives, and does _not_ emit handwritten triple-slash directives to output files unless those directives are marked as [`preserve="true"`](#preservetrue).
17
+
16
18
## `/// <reference path="..." />`
17
19
18
20
The `/// <reference path="..." />` directive is the most common of this group.
@@ -55,11 +57,6 @@ An easy way to think of triple-slash-reference-types directives are as an `impor
55
57
For example, including `/// <reference types="node" />` in a declaration file declares that this file uses names declared in `@types/node/index.d.ts`;
56
58
and thus, this package needs to be included in the compilation along with the declaration file.
57
59
58
-
Use these directives only when you're authoring a `d.ts` file by hand.
59
-
60
-
For declaration files generated during compilation, the compiler will automatically add `/// <reference types="..." />` for you;
61
-
A `/// <reference types="..." />` in a generated declaration file is added _if and only if_ the resulting file uses any declarations from the referenced package.
62
-
63
60
For declaring a dependency on an `@types` package in a `.ts` file, use [`types`](/tsconfig#types) on the command line or in your `tsconfig.json` instead.
64
61
See [using `@types`, `typeRoots` and `types` in `tsconfig.json` files](/docs/handbook/tsconfig-json.html#types-typeroots-and-types) for more details.
65
62
@@ -142,3 +139,24 @@ define(["require", "exports", "legacy/moduleA"], function (
142
139
moduleA.callStuff();
143
140
});
144
141
```
142
+
143
+
144
+
## `preserve="true"`
145
+
146
+
Triple-slash directives can be marked with `preserve="true"` to prevent the compiler from removing them from the output.
0 commit comments