TypeScript Definitely Typed


Understanding DefinitelyTyped in TypeScript

Many JavaScript libraries available on NPM weren’t written with TypeScript in mind. This means they don’t come with built-in type definitions out of the box.

To solve this problem, the TypeScript community maintains a massive collection of type definitions for popular JavaScript libraries. This initiative is called DefinitelyTyped.


What is DefinitelyTyped?

DefinitelyTyped is an open-source project that hosts TypeScript declaration files (.d.ts) for hundreds (actually, thousands) of popular JavaScript libraries that don't ship with native types.

These definitions are published to NPM under the @types scope.


How to Add Types for a Library

You can install type declarations for a package using:

npm install --save-dev @types/lodash

In this example, the lodash library doesn’t include TypeScript definitions itself, but you can use it safely in TypeScript once you’ve installed its matching @types/lodash package.


Zero Setup Needed After Installation

After you install the @types/ package, TypeScript will automatically detect the type declarations and use them in your project. You don’t need to import anything manually—just use the library like normal.


Editor Integration

Modern editors like VS Code help streamline this process by offering suggestions when types are missing. For example, if you use express and types aren’t present, the editor might prompt you to run:

npm install --save-dev @types/express

This makes your development smoother and safer without needing to search manually.


Prefer Learning by Watching?

Watch these YouTube tutorials to understand TYPESCRIPT Tutorial visually:

What You'll Learn:
  • 📌 TypeScript - Definitely Typed | d.ts file | Using Javascript libraries in Typescript
  • 📌 How Definitely Typed Changed TypeScript Forever | React Universe On Air #26
Previous