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:
parent
81f8585643
commit
2aa45f880e
1 changed files with 10 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue