You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(linter): Improve docs, diagnostic message, and implementation of typescript/consistent-indexed-object-style rule. (#15750)
Diagnostic messages are grammatically correct and also tell the user what to actually do now. And the implementation of the rule has been refactored a bit to ensure the enum is used for the config options rather than a boolean, which was confusing (especially in the generated docs).
Docs now look like this:
### What it does
Choose between requiring either `Record` type or indexed signature types.
These two types are equivalent, this rule enforces consistency in picking one style over the other:
```ts
type Foo = Record<string, unknown>;
type Foo = {
[key: string]: unknown;
}
```
### Why is this bad?
Inconsistent style for indexed object types can harm readability in a project.
### Examples
Examples of **incorrect** code for this rule with
`consistent-indexed-object-style: ["error", "record"]` (default):
```ts
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
```
Examples of **correct** code for this rule with
`consistent-indexed-object-style: ["error", "record"]` (default):
```ts
type Foo = Record<string, unknown>;
```
Examples of **incorrect** code for this rule with
`consistent-indexed-object-style: ["error", "index-signature"]`:
```ts
type Foo = Record<string, unknown>;
```
Examples of **correct** code for this rule with
`consistent-indexed-object-style: ["error", "index-signature"]`:
```ts
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
```
## Configuration
This rule accepts a configuration object with the following properties:
### preferredStyle
type: `"record" | "index-signature"`
default: `"record"`
When set to `record`, enforces the use of a `Record` for indexed object types, e.g. `Record<string, unknown>`.
When set to `index-signature`, enforces the use of indexed signature types, e.g. `{ [key: string]: unknown }`.
0 commit comments