typescript/consistent-indexed-object-style Style
What it does
Choose between requiring either Record
type or indexed signature types.
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 the default "record":
ts
/*eslint consistent-indexed-object-style: ["error", "record"]*/
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
Examples of correct code for this rule:
ts
/*eslint consistent-indexed-object-style: ["error", "record"]*/
type Foo = Record<string, unknown>;
Examples of incorrect code for this rule with "index-signature":
ts
/*eslint consistent-indexed-object-style: ["error", "index-signature"]*/
type Foo = Record<string, unknown>;
Examples of correct code for this rule:
ts
/*eslint consistent-indexed-object-style: ["error", "index-signature"]*/
interface Foo {
[key: string]: unknown;
}
type Foo = {
[key: string]: unknown;
};
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny typescript/consistent-indexed-object-style
json
{
"rules": {
"typescript/consistent-indexed-object-style": "error"
}
}