indexedObjectTypes
Reports indexed object types that don't match the configured style.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
TypeScript provides two equivalent ways to define indexed object types: Record<K, V> and { [key: K]: V }.
Using one style consistently improves code readability.
This rule enforces consistent usage of either Record<K, V> (default) or index signatures.
Examples
Section titled “Examples”interface interface Data
Data { [key: string
key: string]: number;}type type StringMap = { [key: string]: string;}
StringMap = { [key: string
key: string]: string };function function process(data: { [key: string]: number;}): void
process(data: { [key: string]: number;}
data: { [key: string
key: string]: number }): void {}type type Data = { [x: string]: number;}
Data = type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record<string, number>;type type StringMap = { [x: string]: string;}
StringMap = type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record<string, string>;function function process(data: Record<string, number>): void
process(data: Record<string, number>
data: type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record<string, number>): void {}Options
Section titled “Options”"record"(default): PreferRecord<K, V>over index signatures."index-signature": Prefer index signatures overRecord<K, V>.
When set to "index-signature":
type type Data = { [x: string]: number;}
Data = type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record<string, number>;type type Data = { [key: string]: number;}
Data = { [key: string
key: string]: number };When Not To Use It
Section titled “When Not To Use It”If your project already has an established convention for indexed object types that you don’t want to enforce, or if you prefer allowing both styles for flexibility, you may disable this rule.