declaration file
A file ending in .d.ts that contains only type information describing JavaScript that exists elsewhere, with no runnable code.
In more detail
tsc can generate them next to your JavaScript so other projects get your types. Packages written in plain JavaScript get theirs from @types packages. They are where ambient declarations and module augmentation usually live.
Related terms
- ambient declaration — A declaration starting with declare, which tells the compiler something exists at run time without generating any code for it.
- DefinitelyTyped — The community repository of type declarations for JavaScript packages, published to npm as @types/package-name.
- module augmentation — Adding types to another package from your own code with declare module "name" { } and declaration merging.
- skipLibCheck — The compiler option that skips type checking of all declaration files, including those of installed packages, to speed up builds.
Taught in
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript