# @typescript-eslint/no-restricted-types

> Disallow the types you list

Some types shouldn't be used in your project, like a deprecated type, one that's easy to confuse with another, or one the project has a better name for. You list them, and the rule reports every use as a type.

The rule does nothing until you give it options.

`--fix` replaces a type if you set `fixWith` for it.

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

## Configure

Off by default. To turn it on:

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

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-restricted-types" = ["error", {
  # types = <object>,
}]
```

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

## Examples

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-restricted-types" = ["error", {
  types = { LegacyUser = "Use Account instead." },
}]
```

Reported:

{/* bad {"options": [{"types": {"LegacyUser": "Use Account instead."}}]} */}
```ts
interface LegacyUser {
  name: string;
}

function greet(user: LegacyUser) {
  return user.name;
}
```

Not reported:

{/* good {"options": [{"types": {"LegacyUser": "Use Account instead."}}]} */}
```ts
interface Account {
  name: string;
}

function greet(user: Account) {
  return user.name;
}
```

## Options

`types` is an object. Each key is a type as you write it in code, and spaces don't matter. It can be a name (`LegacyUser`, `NodeJS.Timeout`), a name with type arguments (`Array<any>`), a keyword other than `any` (`object`, `null`, `unknown`), or the empty `{}` and `[]`.

| Value | What it does |
| --- | --- |
| `true` | Report the type. |
| A string | Report the type, with this text after the message. |
| `{ "message": .., "fixWith": .., "suggest": [..] }` | `message` is the text. `fixWith` is what `--fix` writes in its place. `suggest` lists replacements that an editor offers. All three are optional. |

A name matches no matter what its type arguments are. With `{ Record: true }`, both lines are reported:

{/* bad {"count": 2, "options": [{"types": {"Record": true}}]} */}
```ts
let scores: Record<string, number>;
let flags: Record<string, boolean>;
```

A key with type arguments matches only those. With the key `"Record<string, any>"`, only the second line is reported:

{/* bad {"count": 1, "options": [{"types": {"Record<string, any>": {"message": "Use unknown.", "fixWith": "Record<string, unknown>"}}}]} */}
```ts
let scores: Record<string, number>;
let body: Record<string, any>;
```

Only types are reported, not values with the same name. With `{ Object: true }`, this is allowed:

{/* good {"options": [{"types": {"Object": true}}]} */}
```ts
const keys = Object.keys({ a: 1 });
```
