persona-community-5/.pnpm-store/v3/files/38/d56ffd557efeaf1d8f39696812cbbc6257b0025ea9114bf08c10d073199dfe26370aba72cc9b8c31786d61126c3a6555188428eac89a23bf2567cf440be902
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

90 lines
1.8 KiB
Plaintext

---
description: 'Require or disallow the `Record` type.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/consistent-indexed-object-style** for documentation.
TypeScript supports defining arbitrary object keys using an index signature. TypeScript also has a builtin type named `Record` to create an empty object defining only an index signature. For example, the following types are equal:
```ts
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
type Foo = Record<string, unknown>;
```
Using one declaration form consistently improves code readability.
## Options
- `"record"` _(default)_: only allow the `Record` type.
- `"index-signature"`: only allow index signatures.
### `record`
<Tabs>
<TabItem value="❌ Incorrect">
```ts option='"record"'
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
```
</TabItem>
<TabItem value="✅ Correct">
```ts option='"record"'
type Foo = Record<string, unknown>;
```
</TabItem>
</Tabs>
### `index-signature`
<Tabs>
<TabItem value="❌ Incorrect">
```ts option='"index-signature"'
type Foo = Record<string, unknown>;
```
</TabItem>
<TabItem value="✅ Correct">
```ts option='"index-signature"'
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
```
</TabItem>
</Tabs>
## When Not To Use It
This rule is purely a stylistic rule for maintaining consistency in your project.
You can turn it off if you don't want to keep a consistent style for indexed object types.
However, keep in mind that inconsistent style can harm readability in a project.
We recommend picking a single option for this rule that works best for your project.