Skip to main content

prefer-type-fest-union-to-tuple

Require TypeFest UnionToTuple<T> over legacy union-to-tuple aliases.

Targeted pattern scope​

This rule targets imported alias names that represent union-to-tuple conversion semantics (for example, TuplifyUnion and TupleFromUnion).

What this rule reports​

  • Type references that resolve to imported union-to-tuple aliases.

Why this rule exists​

UnionToTuple is TypeFest’s canonical helper for converting unions to tuple forms. Using one canonical helper improves readability and migration consistency.

❌ Incorrect​

import type { TuplifyUnion } from "type-aliases";

type KeysTuple = TuplifyUnion<"a" | "b" | "c">;

βœ… Correct​

import type { UnionToTuple } from "type-fest";

type KeysTuple = UnionToTuple<"a" | "b" | "c">;

Behavior and migration notes​

  • UnionToTuple<T> converts union members into an unordered tuple.
  • This rule only targets known alias names with equivalent intent.
  • Keep custom aliases only when they intentionally provide additional behavior.

Additional examples​

❌ Incorrect β€” Additional example​

import type { TupleFromUnion } from "type-aliases";

type NumericTuple = TupleFromUnion<1 | 2 | 3>;

βœ… Correct β€” Additional example​

import type { UnionToTuple } from "type-fest";

type NumericTuple = UnionToTuple<1 | 2 | 3>;

βœ… Correct β€” Repository-wide usage​

type AllowedTuple = UnionToTuple<AllowedValue>;

ESLint flat config example​

import typefest from "eslint-plugin-typefest";

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

When not to use it​

Disable this rule if compatibility requirements mandate custom alias names.

Package documentation​

TypeFest package documentation:

Source file: source/union-to-tuple.d.ts

/**
Convert a union type into an unordered tuple type of its elements.

@category Array
*/
export type UnionToTuple<T, L = UnionMember<T>> = ...

Rule catalog ID: R083

Further reading​

Adoption resources​