[!IMPORTANT]
The Merge and MergeDeep types from type-fest are great additions to this library. It is not unreasonable to use those types for your merge typing needs.
Without explicitly passing in types the function will infer the shape of the object(s) passed in.
Passing in TData will validate the shape of the objects passed in.
Passing in TResult will override the output type. While this should be used sparingly, it provides a convenient approach for correctly typing partial types into complete types.
Simple Example w/o Generics
type Data = { name: string; description: string;};const base: Data = { name: "object-deep-merge", description: "merge objects" };const overrides: Partial<Data> = { description: "merge objects, deeply" };const merged = merge(base, overrides);// Type is inferred so the signature becomes:// function merge<Partial<Data>, Partial<Data>>(source: Partial<Data>, target: Partial<Data>, ...targets: Partial<Data>[]): Partial<Data>// TData = Partial<Data>// TResult = Dataconsole.log({ merged });
[!NOTE]
Passing in TResult will override the output type. While this should be used sparingly, it provides a convenient approach for correctly typing partial types into complete types.