Skip to main content

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] when values resolves 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] when values resolves to an array-like type.
  • It does not report number-indexed object maps.
  • It does not report plain T[number]; use prefer-type-fest-array-element for 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

Further readingโ€‹

Adoption resourcesโ€‹