Declarations for TypeScripts
Declarations are how TypeScript learns the types of code it did not compile. Declaration files with the .d.ts extension describe the shapes of JavaScript libraries, and packages from DefinitelyTyped provide them under the @types scope. This unit also covers migrating a JavaScript codebase step by step, using allowJs, checkJs and gradual typing.
Stage: Project Setup · Part of the TypeScript roadmap · Last reviewed 19 November 2026
What to learn in Declarations
- Install @types packages for a JavaScript library and use its types
- Write a minimal .d.ts file for an untyped module
- Augment a global or module type, such as adding a property to Request
- Enable allowJs and checkJs to type check existing JavaScript
- Plan an incremental migration that converts files one at a time
Declarations interview questions
What is a .d.ts file?
A declaration file contains only type information, with no runtime code. It describes the exported functions, classes and values of a JavaScript module so the compiler and editor can check usage. Libraries ship them, or you get them from the @types packages.
How would you migrate a large JavaScript project to TypeScript?
Migrate gradually. Add tsconfig with allowJs, rename files to .ts one at a time starting with leaf modules, begin with lenient settings and tighten strictness later, and keep tests passing. Add types to shared utilities and API boundaries first for the most benefit.
Where Declarations fits in the TypeScript roadmap
Declarations belongs to the Project Setup stage (intermediate level), which takes about 17 hours. Compile and configure.
Other units in this stage
Back to the full TypeScript roadmap