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.
K
The target type (typically a union)
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 } Copy
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 } Copy
type Result = Normalize< | { type: "a"; a: string } | { type: "b"; b: number }, "a">;// ^?// | { type: "a"; a: string }// | { type: "b"; a?: never; b: number }
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.