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