# @typescript-eslint/no-deprecated

> Disallow using code marked as `@deprecated`

A `@deprecated` tag in a doc comment says that a function, class, property or type is going away, and usually what to use instead. Editors strike the name through, but nothing stops new code from using it. This rule reports every use, and repeats the text after the tag so you know what to switch to.

It works for your own code, for packages and for the built-in types. The declaration itself and the `import` aren't reported, only the places where the name is used. If only one overload of a function is deprecated, only calls to that overload are reported.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. This rule needs types, so turning it on makes `bun lint` type check your code first.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-deprecated" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-deprecated" = ["error", {
  allow = [], # list of strings or objects
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}

interface Options {
  /** @deprecated */
  legacy?: boolean;
}

getUser(1);

function start(options: Options) {
  return options.legacy;
}
```

Built-in methods count too:

{/* bad */}
```ts
const year = "2026-01-01".substr(0, 4);
```

Not reported:

{/* good */}
```ts
/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}

function fetchUser(id: number) {}

fetchUser(1);

const year = "2026-01-01".slice(0, 4);
```

Only the deprecated overload:

{/* bad {"count": 1} */}
```ts
/** @deprecated Pass a number. */
function load(id: string): void;
function load(id: number): void;
function load(id: string | number): void {}

load("1");
load(1);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allow` | `[]` | Deprecated names that you can keep using. |

Each `allow` entry is a name, or an object that also says where the name comes from:

| Entry | What it matches |
| --- | --- |
| `"getUser"` | Anything with that name. |
| `{ "from": "file", "name": "getUser" }` | A name declared in your project. Add `"path"` to name the file. |
| `{ "from": "lib", "name": "substr" }` | A name from the built-in TypeScript types. |
| `{ "from": "package", "name": "exists", "package": "fs" }` | A name from a package. |

`name` can also be a list of names.

{/* good {"options": [{"allow": [{"from": "file", "name": "getUser"}]}]} */}
```ts
/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}

getUser(1);
```

{/* good {"options": [{"allow": [{"from": "lib", "name": "substr"}]}]} */}
```ts
const year = "2026-01-01".substr(0, 4);
```
