type-only import
An import written import type { X } or import { type X }, which brings in only types and is always removed from the output.
In more detail
Because the whole statement disappears on compile, a single-file transpiler never emits an import of something that does not exist at run time. verbatimModuleSyntax requires them for every import that is only used as a type.
Examples
import type { ClientOptions } from "./client.js";import { ApiClient, type ClientOptions } from "./client.js";Related terms
- verbatimModuleSyntax — The compiler option that keeps every import and export exactly as written, except those marked type, which are removed.
- type erasure — The removal of all TypeScript types when code is compiled, so none of them exist while the JavaScript runs.
- import and export — The statements that share code between modules: export makes a name available, import brings it into another file.
Taught in
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript