Skip to main content

prefer-type-fest-is-tuple

Require TypeFest IsTuple<T> over manual length-based tuple conditional type guards.

Targeted pattern scopeโ€‹

This rule reports exact conditional type guards shaped like number extends T["length"] ? false : true.

What this rule reportsโ€‹

This rule reports manual tuple detection helpers that can be replaced by IsTuple<T>.

  • number extends T["length"] ? false : true

Why this rule existsโ€‹

IsTuple<T> documents the intent directly and centralizes TypeFest's tuple handling instead of repeating a low-level indexed-access check.

โŒ Incorrectโ€‹

type Result<T extends readonly unknown[]> =
number extends T["length"] ? false : true;

โœ… Correctโ€‹

type Result<T extends readonly unknown[]> = IsTuple<T>;

Behavior and migration notesโ€‹

  • The rule intentionally requires the exact number extends T["length"] ? false : true shape.
  • The opposite array-detection shape, number extends T["length"] ? true : false, is ignored.
  • Autofix is skipped when IsTuple is shadowed in the local scope.

Additional examplesโ€‹

โœ… Correct โ€” Existing utilityโ€‹

type Result<T extends readonly unknown[]> = IsTuple<T>;

โœ… Correct โ€” Array guardโ€‹

type Result<T extends readonly unknown[]> =
number extends T["length"] ? true : false;

ESLint flat config exampleโ€‹

import typefest from "eslint-plugin-typefest";

export default [
{
plugins: { typefest },
rules: {
"typefest/prefer-type-fest-is-tuple": "error",
},
},
];

When not to use itโ€‹

Disable this rule if a public type alias must preserve a hand-written conditional for compatibility documentation.

Package documentationโ€‹

TypeFest package documentation:

Source file: source/is-tuple.d.ts

Rule catalog ID: R112

Further readingโ€‹

Adoption resourcesโ€‹