TS Definitely Typed

DefinitelyTyped & @types

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.


1. Installing Type Definitions

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.

NPM Install Example:

# Install the actual library
npm install lodash
# Install the community-maintained type definitions
npm install -D @types/lodash

2. Declaration Files (.d.ts)

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.

Declaration File Example:

// Inside a custom myModule.d.ts file
declare module "my-custom-library" {
  export function calculate(a: number): number;
  export const version: string;
}

3. SEO and Ecosystem Integration

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.

Node Setup Example:

# Required to use native Node.js modules like 'fs' and 'path'
npm install -D @types/node
# Now you can import them securely!

Exercise

?

Which NPM scope is used to download community-maintained TypeScript definitions?


4. Final Thoughts

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!