prefer-type-fest-array-element
Require TypeFest ArrayElement<T> over array and tuple T[number] element extraction.
Targeted pattern scopeโ
This is a type-aware rule. It targets indexed-access type queries whose object type resolves to an array or tuple.
What this rule reportsโ
T[number]whenTresolves to an array or tuple type.
The rule intentionally skips typeof values[number]. Use a dedicated ArrayValues rule for extracting values from constant arrays.
Why this rule existsโ
ArrayElement<T> is the dedicated TypeFest helper for array and tuple element extraction. Using it makes intent explicit and avoids repeating raw numeric indexed-access syntax in shared type helpers.
โ Incorrectโ
type Step = EventSteps[number];
โ Correctโ
import type { ArrayElement } from "type-fest";
type Step = ArrayElement<EventSteps>;
Behavior and migration notesโ
- This rule requires type information.
- It only reports
T[number]whenTresolves to an array-like type. - It does not report number-indexed object maps like
Record<number, string>[number]. - It leaves
typeof values[number]alone forArrayValues<typeof values>coverage.
Additional examplesโ
โ Incorrect โ Additional exampleโ
type UserItem = User["items"][number];
โ Correct โ Additional exampleโ
import type { ArrayElement } from "type-fest";
type UserItem = ArrayElement<User["items"]>;
โ Correct โ Non-targeted usageโ
const statuses = ["queued", "running"] as const;
type Status = typeof statuses[number];
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-array-element": "error",
},
},
];
When not to use itโ
Disable this rule if you prefer native indexed-access syntax for array element queries or if your project does not use type-aware linting.
Package documentationโ
TypeFest package documentation:
Source file: source/array-element.d.ts
export type ArrayElement<T> =
T extends UnknownArray
? T[number]
: never;
Rule catalog ID: R109