# typedef

Rule `typescript/typedef`. Require type annotations in certain places

- Source: typescript
- Technologies: TypeScript
- Kind: style
- Needs type information: no
- Autofix: no
- Deprecated: yes
- Reach: 31.4K weekly downloads of presets that enable it
- Trend: +32.4% last quarter
- Rank: #1646 by reach, #1086 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/typedef` | no | no | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/typedef) |

## Code examples

### Incorrect: the rule reports this

```ts
const [a] = [1];
const [b, c] = [1, 2];
```

```ts
const logsSize = size => console.log(size);

['hello', 'world'].map(text => text.length);

const mapper = {
  map: text => text + '...',
};
```

```ts
class ContainsText {
  delayedText;
  immediateTextImplicit = 'text';
}
```

### Correct: the rule accepts this

```ts
const [a]: number[] = [1];
const [b]: [number] = [2];
const [c, d]: [boolean, string] = [true, 'text'];

for (const [key, val] of new Map([['key', 1]])) {
}
```

```ts
const logsSize = (size: number) => console.log(size);

['hello', 'world'].map((text: string) => text.length);

const mapper = {
  map: (text: string) => text + '...',
};
```

```ts
class ContainsText {
  delayedText: string;
  immediateTextImplicit: string = 'text';
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/typedef": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Alloy](https://lintradar.dev/presets/alloy.md) | ESLint | `eslint-config-alloy` | 166 | 31.4K | +32.4% |

## Related rules

- [typescript/no-invalid-this](https://lintradar.dev/rules/typescript/no-invalid-this.md): Disallow `this` keywords outside of classes or class-like objects
- [typescript/member-ordering](https://lintradar.dev/rules/typescript/member-ordering.md): Require a consistent member declaration order
- [typescript/init-declarations](https://lintradar.dev/rules/typescript/init-declarations.md): Require or disallow initialization in variable declarations
- [typescript/class-methods-use-this](https://lintradar.dev/rules/typescript/class-methods-use-this.md): Enforce that class methods utilize `this`
- [typescript/prefer-destructuring](https://lintradar.dev/rules/typescript/prefer-destructuring.md): Require destructuring from arrays and/or objects
- [typescript/explicit-module-boundary-types](https://lintradar.dev/rules/typescript/explicit-module-boundary-types.md): Require explicit return and argument types on exported functions' and classes' public class methods

---

Web page: https://lintradar.dev/rules/typescript/typedef. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
