Deeply merge two types recursively, with B taking precedence over A.
Primitives (including Date, RegExp, Map, Set, etc.): B overwrites A.
Arrays: element types are merged via DeepMerge and wrapped in Array<>.
This is safe for both the 'replace' and 'concat' array strategies at runtime.
Plain objects: properties are recursively merged. Keys present only in A
keep their original type; keys present only in B use B's type; overlapping
keys are deeply merged with B's property taking precedence.
Mixed types (e.g. A is an object, B is a primitive): B wins.
Type Parameters
A
The base type (lower precedence).
B
The overriding type (higher precedence).
Example
typeUser = { name: string; meta: { visits: number } }; typePatch = { meta: { lastSeen: Date }; age: number }; typeMerged = DeepMerge<User, Patch>; // Merged = { name: string; meta: { visits: number; lastSeen: Date }; age: number }
Deeply merge two types recursively, with
Btaking precedence overA.Date,RegExp,Map,Set, etc.):BoverwritesA.DeepMergeand wrapped inArray<>. This is safe for both the'replace'and'concat'array strategies at runtime.Akeep their original type; keys present only inBuseB's type; overlapping keys are deeply merged withB's property taking precedence.Ais an object,Bis a primitive):Bwins.