Most of the popular libraries on NPM were written in plain JavaScript, not TypeScript.
This means they natively lack type definitions, which breaks IntelliSense.
DefinitelyTyped is a massive open-source repository that solves this exact problem.
It provides high-quality TypeScript definitions for almost every JavaScript library.
You install these definitions via NPM using the @types/ namespace scope.
For example, if you install lodash, you should also install @types/lodash.
You typically install them as development dependencies using the -D flag.
# Install the actual library npm install lodash # Install the community-maintained type definitions npm install -D @types/lodash
Type definitions are stored in special files ending with the .d.ts extension.
These files do not contain actual logic or executable JavaScript code.
They only contain structural interfaces and type signatures for the compiler to read.
// Inside a custom myModule.d.ts file
declare module "my-custom-library" {
export function calculate(a: number): number;
export const version: string;
}
Using DefinitelyTyped allows you to safely use massive SEO-friendly JS libraries.
You get full type checking on libraries like React, Express, and jQuery instantly.
It merges the dynamic JS ecosystem with the strictness of enterprise software engineering.
# Required to use native Node.js modules like 'fs' and 'path' npm install -D @types/node # Now you can import them securely!
Which NPM scope is used to download community-maintained TypeScript definitions?
Without DefinitelyTyped, adopting TypeScript would have been practically impossible for most.
It is one of the most vibrant open-source projects on GitHub today.
Next, we will explore configuring the compiler using tsconfig.json!