0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

docs: fix issue in manual regarding how to reference types in JavaScript (#10573)

Fixes: #10561
This commit is contained in:
Kitson Kelly 2021-05-11 15:04:00 +10:00 committed by GitHub
parent 81f8585643
commit 2aa45f880e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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