indexedObjectTypes
Reports indexed object types that don't match the configured style.
✅ This rule is included in the ts stylistic presets.
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 Data { [key: string]: number;}type StringMap = { [key: string]: string };function process(data: { [key: string]: number }): void {}type Data = Record<string, number>;type StringMap = Record<string, string>;function process(data: 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 Data = Record<string, number>;type Data = { [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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.