@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Type Alias UnionToTuple<T, L>

    UnionToTuple: IsNever<T> extends false
        ? [...UnionToTuple<Exclude<T, L>>, L]
        : []

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

    "Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.

    This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.

    将联合类型转换为其元素的无序元组类型。

    “无序”意味着元组中的元素不一定与联合类型中的顺序相同。排列可以显得随机,并且可能会随时改变。

    当你有具有有限键集的对象,并且希望定义仅允许的键的类型,但又不想重复自己时,这会很有用。

    Type Parameters

    • T

      要转换的联合类型

    • L = LastOfUnion<T>

      内部使用的类型参数

    type Numbers = 1 | 2 | 3
    type NumbersTuple = UnionToTuple<Numbers>
    //=> [1, 2, 3]
    const pets = {
    dog: '🐶',
    cat: '🐱',
    snake: '🐍',
    }

    type Pet = keyof typeof pets;
    //=> 'dog' | 'cat' | 'snake'

    const petList = Object.keys(pets) as UnionToTuple<Pet>;
    //=> ['dog', 'cat', 'snake']