Type alias KeysOfUnion<T>

KeysOfUnion<T>: T extends T
    ? keyof T
    : never

KeysOfUnion extracts the union of keys from a given union of object types. This is useful in scenarios where you need to access all possible keys across unioned object types within conditional or mapped types.

Type Parameters

  • T

    The union of object types to extract keys from.

Example

type UnionKeys = KeysOfUnion<{ a: string } | { b: number }>; // Result: 'a' | 'b'