utilitypes-ts
    Preparing search index...

    Type Alias UnionKey<T>

    UnionKey: T extends T ? keyof T : never

    Extracts all keys from a union type.

    Unlike keyof, which only returns keys common to all members, this type returns all keys across the given union

    Type Parameters

    • T
    type Result = UnionKey<
    | { a: string }
    | { b: number }
    >;
    // ^?
    // "a" | "b"