diff options
Diffstat (limited to 'docs/getting_started')
-rw-r--r-- | docs/getting_started/typescript.md | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/docs/getting_started/typescript.md b/docs/getting_started/typescript.md index 972d42713..6aa738c88 100644 --- a/docs/getting_started/typescript.md +++ b/docs/getting_started/typescript.md @@ -23,23 +23,20 @@ useful when type checking is provided by your editor and you want startup time to be as fast as possible (for example when restarting the program automatically with a file watcher). -Because `--no-check` does not do TypeScript type checking we can not -automatically remove type only imports and exports as this would require type -information. For this purpose TypeScript provides the -[`import type` and `export type` syntax](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-exports). -To export a type in a different file use -`export type { AnInterface } from "./mod.ts";`. To import a type use -`import type { AnInterface } from "./mod.ts";`. You can check that you are using -`import type` and `export type` where necessary by setting the `isolatedModules` -TypeScript compiler option to `true`, and the `importsNotUsedAsValues` to -`error`. You can see an example `tsconfig.json` with this option -[in the standard library](https://github.com/denoland/deno/blob/$CLI_VERSION/std/tsconfig_test.json). -These settings will be enabled by default in the future. They are already the -default in Deno 1.4 or above when using `--unstable`. - -Because there is no type information when using `--no-check`, `const enum` is -not supported because it is type-directed. `--no-check` also does not support -the legacy `import =` and `export =` syntax. +To make the most of skipping type checks, `--no-check` transpiles each module in +isolation without using information from imported modules. This maximizes +potential for concurrency and incremental rebuilds. On the other hand, the +transpiler cannot know if `export { Foo } from "./foo.ts"` should be preserved +(in case `Foo` is a value) or removed (in case `Foo` is strictly a type). To +resolve such ambiguities, Deno enforces +[`isolatedModules`](https://www.typescriptlang.org/tsconfig#isolatedModules) on +all TS code. This means that `Foo` in the above example must be a value, and the +[`export type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-exports) +syntax must be used instead if `Foo` is a type. + +Another consequence of `isolatedModules` is that the type-directed `const enum` +is treated like `enum`. The legacy `import =` and `export =` syntaxes are also +not supported by `--no-check`. ### Using external type definitions @@ -90,7 +87,7 @@ definition which happens to be alongside that file, your JavaScript module named export const foo = "foo"; ``` -Deno will see this, and the compiler will use `foo.d.ts` when type checking the +Deno will see this, and the compiler will use `foo.d.ts` when type-checking the file, though `foo.js` will be loaded at runtime. The resolution of the value of the directive follows the same resolution logic as importing a module, meaning the file needs to have an extension and is relative to the current file. Remote |