typelab / utils / ObjectUnionize
type ObjectUnionize<Target, UnionType, Z> = IsObjectLiteral<Target> extends true ? { [K in keyof Target]: _Lookup<Z, { shallow: Target[K] | UnionType; deep: _ObjectUnionizeDeep<Target[K], UnionType> }> } : never;Unions the properties of an object with a specified UnionType, creating a new object where each property
is either the original value or the UnionType.
This type will unionize all nested object types (if Z is 'deep').
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The |
|
|
‐ |
The type to union with each property of the |
|
|
|
Defines the lookup type, which can be |
// { a: string | number; b: number | { a: string; }; }
type Shallow = ObjectUnionize<{ a: string; b: { a: string } }, number, 'shallow'>;
// { a: string | number; b: { a: string | number; }; }
type Deep = ObjectUnionize<{ a: string; b: { a: string } }, number, 'deep'>;