Skip to content

Commit cec2e03

Browse files
authored
Add /// <reference lib="..." /> docs
1 parent 0819fcd commit cec2e03

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pages/Triple-Slash Directives.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ A `/// <reference types="..." />` in a generated declaration file is added *if a
5656
For declaring a dependency on an `@types` package in a `.ts` file, use `--types` on the command line or in your `tsconfig.json` instead.
5757
See [using `@types`, `typeRoots` and `types` in `tsconfig.json` files](./tsconfig.json.md#types-typeroots-and-types) for more details.
5858

59+
## `/// <reference lib="..." />`
60+
61+
This directive allows a file to explicitly include an existing built-in _lib_ file.
62+
63+
Built-in _lib_ files are referenced in the same fashion as the `"lib"` compiler option in _tsconfig.json_ (e.g. use `lib="es2015"` and not `lib="lib.es2015.d.ts"`, etc.).
64+
65+
For declaration file authors who relay on built-in types, e.g. DOM APIs or built-in JS run-time constructors like `Symbol` or `Iterable`, triple-slash-reference lib directives are the recommended. Previously these .d.ts files had to add forward/duplicate declarations of such types.
66+
67+
For example, adding `/// <reference lib="es2017.string" />` to one of the files in a compilation is equivalent to compiling with `--lib es2017.string`.
68+
69+
```ts
70+
/// <reference lib="es2017.string" />
71+
72+
"foo".padStart(4);
73+
```
74+
5975
## `/// <reference no-default-lib="true"/>`
6076

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

0 commit comments

Comments
 (0)