# @typescript-eslint/consistent-indexed-object-style

> Require either `Record<K, V>` or an index signature, consistently

`Record<string, number>` and `{ [key: string]: number }` describe the same object: any string key, with a number as its value. This rule picks one way to write it. By default it's `Record`.

`--fix` rewrites the type to the other form where that's safe.

{/* 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/consistent-indexed-object-style" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
# "record" or "index-signature"
"@typescript-eslint/consistent-indexed-object-style" = ["error", "record"]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
type Scores = { [player: string]: number };

interface Prices {
  [product: string]: number;
}
```

A mapped type that doesn't use its key is also a `Record`:

{/* bad */}
```ts
type Flags = { [Name in "debug" | "verbose"]: boolean };
```

Not reported:

{/* good */}
```ts
type Scores = Record<string, number>;
type Prices = Record<string, number>;
type Flags = Record<"debug" | "verbose", boolean>;
```

An index signature next to other members can't be a `Record`. Neither can a type that refers to itself, because a type alias for `Record` can't be circular:

{/* good */}
```ts
interface Headers {
  [name: string]: string;
  host: string;
}

type Tree = { [name: string]: Tree };
```

## Options

| Option | What it does |
| --- | --- |
| `"record"` (default) | Require `Record<K, V>`. |
| `"index-signature"` | Require `{ [key: K]: V }`. |

{/* bad {"options": ["index-signature"]} */}
```ts
type Scores = Record<string, number>;
```

{/* good {"options": ["index-signature"]} */}
```ts
type Scores = { [player: string]: number };
```
