From 2aa45f880ed1a970324214bb3cee098d98453104 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 11 May 2021 15:04:00 +1000 Subject: docs: fix issue in manual regarding how to reference types in JavaScript (#10573) Fixes: #10561 --- docs/typescript/types.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'docs/typescript/types.md') 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 -/// +/// // ... 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 -- cgit v1.2.3