typelab / utils / ObjectOverwrite
type ObjectOverwrite<Target, Source, Z> = IsNever<Source> extends true ? Target : IsNonNullish<Source> extends true ? Target : IsEqual<Source, Target> extends true ? Source : _ObjectOverwrite<Target, Source, Z>;Overwrite properties of Target with properties of Source.
This type will overwrite all nested object types (if Z is 'deep').
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The |
|
|
|
The |
|
|
|
Defines the lookup type, which can be |
A new object type that overwrites and combines the properties of both Target and Source.
type Obj1 = { a: string; b: string; c: { a: string } };
type Obj2 = { b: number; c: { b: number }; d: number };
// { a: string; b: number; c: { b: number; }; d: number }
type Shallow = ObjectOverwrite<Obj1, Obj2, 'shallow'>;
// { a: string; b: number; c: { a: string; b: number; }; d: number }
type Deep = ObjectOverwrite<Obj1, Obj2, 'deep'>;