utilitypes-ts
    Preparing search index...

    Type Alias Normalize<T, K>

    Normalize: T extends null
    | undefined
        ? T
        : T & Partial<Record<Exclude<K, keyof T>, never>>

    Normalizes a union type so that all members share the same set of keys, making the union easier to work with (e.g. for autocomplete or narrowing).

    By default, all keys from the union are normalized, but you can limit normalization to a subset of keys via K.

    Type Parameters

    • T

      The target type (typically a union)

    • K extends UnionKey<T> = UnionKey<T>

      Keys to normalize (defaults to all keys of the union)

    type Result = Normalize<
    | { type: "a"; a: string }
    | { type: "b"; b: number }
    >;
    // ^?
    // | { type: "a"; a: string; b?: never }
    // | { type: "b"; a?: never; b: number }
    type Result = Normalize<
    | { type: "a"; a: string }
    | { type: "b"; b: number },
    "a"
    >;
    // ^?
    // | { type: "a"; a: string }
    // | { type: "b"; a?: never; b: number }