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