diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-05-11 15:04:00 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 15:04:00 +1000 |
commit | 2aa45f880ed1a970324214bb3cee098d98453104 (patch) | |
tree | 363477f3a363e578bd9d8a7c35a14a460662de8f /docs/typescript | |
parent | 81f8585643faf42edab45f9e8604a0c1d9c7486a (diff) |
docs: fix issue in manual regarding how to reference types in JavaScript (#10573)
Fixes: #10561
Diffstat (limited to 'docs/typescript')
-rw-r--r-- | docs/typescript/types.md | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/docs/typescript/types.md b/docs/typescript/types.md index f1da8fe2e..e2564ce95 100644 --- a/docs/typescript/types.md +++ b/docs/typescript/types.md @@ -61,16 +61,16 @@ types for a given module, without requiring the importer to do anything special. #### Using the triple-slash reference directive -Deno supports using the triple-slash reference directive, which adopts the -reference comment used by TypeScript in TypeScript files to _include_ other -files and applies it to JavaScript files. +Deno supports using the triple-slash reference `types` directive, which adopts +the reference comment used by TypeScript in TypeScript files to _include_ other +files and applies it only to JavaScript files. -For example, if I had create `coolLib.js` and along side of it I had created my +For example, if I had created `coolLib.js` and along side of it I had created my type definitions for my library in `coolLib.d.ts` I could do the following in the `coolLib.js` file: ```js -/// <reference path="./coolLib.d.ts" /> +/// <reference types="./coolLib.d.ts" /> // ... the rest of the JavaScript ... ``` @@ -79,6 +79,11 @@ When Deno encounters this directive, it would resolve the `./coolLib.d.ts` file and use that instead of the JavaScript file when TypeScript was type checking the file, but still load the JavaScript file when running the program. +> ℹ️ _Note_ this is a repurposed directive for TypeScript that only applies to +> JavaScript files. Using the triple-slash reference directive of `types` in a +> TypeScript file works under Deno as well, but has essentially the same +> behavior as the `path` directive. + #### Using X-TypeScript-Types header Similar to the triple-slash directive, Deno supports a header for remote modules |