Definitely Typed (@types) is a massive community repository providing TypeScript type definitions for standard JavaScript libraries (such as Express, React, Node, Lodash) that do not ship with built-in TypeScript definitions.
flowchart LR
A["JavaScript Library (e.g., express)"] --> B["Install @types/express"]
B --> C["node_modules/@types/express/index.d.ts"]
C --> D["TypeScript Compiler Provides Intellisense & Type Checking"]
Installing @types packages as development dependencies:
# Installing type definitions for Node.js and Express
npm install express
npm install --save-dev @types/node @types/express
Writing typed Express handler code:
import express, { Request, Response, NextFunction } from "express";
const app = express();
app.use(express.json());
interface UserParams {
userId: string;
}
interface UserResponseBody {
status: string;
data: { id: string; name: string };
}
app.get("/users/:userId", (req: Request<UserParams>, res: Response<UserResponseBody>) => {
const { userId } = req.params;
res.status(200).json({
status: "success",
data: { id: userId, name: "Developer" }
});
});
console.log("Express router typed successfully.");
@types/* packages using --save-dev since types are only needed at compile-time.axios, zod, rxjs) ship with native TypeScript definitions out-of-the-box, so no @types package is required..d.ts Files: For untyped internal modules, create a custom types/global.d.ts file with declare module 'untyped-pkg';.What command would you run to install TypeScript definitions for the lodash library?
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With