prefer-type-fest-array-values
Require TypeFest ArrayValues<T> over typeof values[number] constant array value extraction.
Targeted pattern scopeโ
This is a type-aware rule. It targets indexed-access type queries whose object type is a typeof query that resolves to an array or tuple.
What this rule reportsโ
typeof values[number]whenvaluesresolves to an array or tuple type.
The rule intentionally leaves non-typeof T[number] patterns to prefer-type-fest-array-element.
Why this rule existsโ
ArrayValues<T> documents the common constant-array pattern directly: derive a union from the values available in a runtime array or tuple.
โ Incorrectโ
const statuses = ["queued", "running"] as const;
type Status = typeof statuses[number];
โ Correctโ
import type { ArrayValues } from "type-fest";
const statuses = ["queued", "running"] as const;
type Status = ArrayValues<typeof statuses>;
Behavior and migration notesโ
- This rule requires type information.
- It only reports
typeof values[number]whenvaluesresolves to an array-like type. - It does not report number-indexed object maps.
- It does not report plain
T[number]; useprefer-type-fest-array-elementfor that pattern.
Additional examplesโ
โ Incorrect โ Additional exampleโ
declare const weekdays: readonly string[];
type WeekdayName = typeof weekdays[number];
โ Correct โ Additional exampleโ
import type { ArrayValues } from "type-fest";
declare const weekdays: readonly string[];
type WeekdayName = ArrayValues<typeof weekdays>;
โ Correct โ Non-targeted usageโ
type Statuses = readonly ["queued", "running"];
type Status = Statuses[number];
ESLint flat config exampleโ
import typefest from "eslint-plugin-typefest";
export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-array-values": "error",
},
},
];
When not to use itโ
Disable this rule if you prefer native indexed-access syntax for value extraction from runtime arrays, or if your project does not use type-aware linting.
Package documentationโ
TypeFest package documentation:
Source file: source/array-values.d.ts
export type ArrayValues<T extends readonly unknown[]> = T[number];
Rule catalog ID: R110