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

Bash

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:

TypeScript

With Definitely Typed → suddenly:

TypeScript

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)

Bash

In TypeScript:

TypeScript

Fix → install types:

Bash

Now magically:

TypeScript

6. How to check if a library needs @types (quick tricks)

  1. npm info library-name → look for “types” or “typings” field in package.json
  2. In VS Code → import → if red squiggles on methods → probably needs types
  3. Search https://www.npmjs.com/package/@types/library-name
  4. Or use https://microsoft.github.io/TypeSearch/ (official search for @types)

7. Common commands / workflows in 2026

Bash

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)

  1. Create a tiny TS project
  2. npm install lodash
  3. Try _.chunk([1,2,3,4], 2) → see any
  4. npm install –save-dev @types/lodash
  5. 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 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *