Chapter 19: TypeScript Definitely Typed
Definitely Typed (often just called DT or @types) like we’re sitting together in a real coding session, with VS Code open, npm terminal ready, and no rush. This is one of the most important ecosystem pieces that makes TypeScript actually usable in the real world.
1. The honest one-sentence version
Definitely Typed is the giant community repository that provides high-quality TypeScript type declaration files (.d.ts) for thousands of JavaScript libraries that were never written in TypeScript (or don’t ship their own types).
These definitions are published to npm under the @types/ scope — so when you do
|
0 1 2 3 4 5 6 7 8 |
npm install --save-dev @types/lodash # or npm install --save-dev @types/react |
you’re pulling types from Definitely Typed.
2. Why does this even exist? (the problem it solves)
Most JavaScript libraries in the world:
- Were written before TypeScript became popular
- Are still plain JS (no .ts files)
- Don’t include .d.ts files in their npm package
Without types → using them in TypeScript gives you:
|
0 1 2 3 4 5 6 7 8 |
import _ from 'lodash'; _.groupBy(users, 'age'); // → any, any, any → no autocompletion, no safety |
With Definitely Typed → suddenly:
|
0 1 2 3 4 5 6 7 8 9 10 11 |
import groupBy from 'lodash/groupBy'; // tree-shake friendly import const result = groupBy(users, 'age'); // result → Record<string, User[]> (or similar accurate type) // Hover → shows full signature // Wrong key → red squiggle immediately |
That’s the magic. Definitely Typed made TypeScript feel native to the entire npm ecosystem — not just to libraries written in TS.
3. How it actually works under the hood (2026 reality)
- Huge GitHub monorepo → https://github.com/DefinitelyTyped/DefinitelyTyped
- Each library lives in its own folder: /types/lodash, /types/express, /types/react, etc.
- Inside each folder:
- index.d.ts (main declarations)
- Sometimes multiple entry points (v4/index.d.ts, fp.d.ts, etc.)
- tsconfig.json for testing
- *.tests.ts files (they type-check the definitions)
- Automated publishing:
- Every PR that gets merged → bot publishes new version to @types/library-name
- Versions usually mirror the JS library version (e.g. @types/react@^18.2.0)
Since ~2023–2024 it became a proper pnpm monorepo → faster installs, better dependency management.
4. The most common ways you meet Definitely Typed every day
| You write this … | What happens behind the scenes | Package source |
|---|---|---|
| npm i axios | Axios ships its own types (built-in) | Inside axios package |
| npm i lodash + npm i -D @types/lodash | Lodash has no types → you need Definitely Typed | @types/lodash ← DT |
| npm i react | React ships its own types since ~16.8 | Inside react + react-dom |
| npm i moment | Moment has types in DT | @types/moment |
| npm i express | Express → needs @types/express + @types/node | DT + DT |
Rule of thumb 2026:
- Modern popular libs (React 18+, Next.js, Zod, TanStack Query, Axios, date-fns v3+, etc.) → usually ship their own types → no @types needed
- Older / less maintained libs (lodash, moment, underscore, request, cheerio, many node modules) → still rely on @types/…
5. Real example walk-through (let’s pretend we’re adding types)
Scenario: You want to use the old request library (hypothetical — it’s deprecated but good teaching case)
|
0 1 2 3 4 5 6 7 |
npm install request # → request@2.88.2 installed |
In TypeScript:
|
0 1 2 3 4 5 6 7 8 9 10 |
import request from 'request'; request('https://api.example.com', (err, res, body) => { // err, res, body → all any :( }); |
Fix → install types:
|
0 1 2 3 4 5 6 |
npm install --save-dev @types/request |
Now magically:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
import request from 'request'; request('https://api.example.com', (err, res, body) => { // err: Error | null | undefined // res: Response (with .statusCode, .headers, .body, etc.) // body: any (still any — but at least request shape is good) }); |
6. How to check if a library needs @types (quick tricks)
- npm info library-name → look for “types” or “typings” field in package.json
- In VS Code → import → if red squiggles on methods → probably needs types
- Search https://www.npmjs.com/package/@types/library-name
- Or use https://microsoft.github.io/TypeSearch/ (official search for @types)
7. Common commands / workflows in 2026
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Install types for a library npm install --save-dev @types/express @types/node @types/jest # If types are missing / outdated → search Definitely Typed issues/PRs # or open a PR yourself (very welcome!) # See all installed @types npm ls | grep @types |
8. Quick status in February 2026
- Repo is healthy & active (tens of PRs per day)
- Still one of the top-contributed repos on GitHub historically
- Many libraries have moved types in-house → number of needed @types slowly decreasing
- But still thousands of packages rely on it (especially Node.js ecosystem, older frontend libs)
9. Mini cheat-sheet table
| Situation | What to do | Example command |
|---|---|---|
| Library ships types | Nothing — just install the lib | npm i zod |
| Library has no types | Install from Definitely Typed | npm i -D @types/lodash |
| Types feel outdated / broken | Check DT GitHub issues/PRs, update or fork | — |
| Want to contribute a missing type | Fork DT, add /types/my-lib, PR | See DT contribution guide |
| Types conflict with built-in | Use skipLibCheck: true or resolutions | tsconfig.json tweak |
Your next mini-step (if you want to play)
- Create a tiny TS project
- npm install lodash
- Try _.chunk([1,2,3,4], 2) → see any
- npm install –save-dev @types/lodash
- See the types appear magically
Any doubt? Want to go deeper into:
- How to actually write & contribute a .d.ts to Definitely Typed (step-by-step)
- When to use declare module “some-lib” local override instead of @types
- Popular @types packages still essential in 2026
- Differences between shipped types vs DT types
Just tell me which direction feels most useful right now 😄
