# Declaration Files (.d.ts) — TypeScript

Source: https://www.geekswithgeeks.com/en/typescript/ts-declaration-files

> Type information for plain JavaScript code, with no runtime cost.

## Types for plain JS

A `.d.ts` file contains only type declarations — no implementation. It describes the shape of a `.js` library so TS can check code that calls it.

## A .d.ts snippet

This describes a JS function's signature without containing its body.

```typescript
// mathLib.d.ts
declare function square(n: number): number;
declare const PI: number;

export { square, PI };
```

## @types packages

For popular JS libraries, someone has usually already written the `.d.ts` — install it with `npm install --save-dev @types/library-name`.
