Skip to content

indexedObjectTypes

Reports indexed object types that don't match the configured style.

✅ This rule is included in the ts stylistic and stylisticStrict 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.

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 {}
  • "record" (default): Prefer Record<K, V> over index signatures.
  • "index-signature": Prefer index signatures over Record<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>;

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.