Skip to main content

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

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.

Back to the full TypeScript roadmap