TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

use recursive partial for type definitions #240

Closed jonnytest1 closed 2 years ago

jonnytest1 commented 2 years ago
export type RecursivePartial<T> = {
  [P in keyof T]?: T[P] extends (infer U)[]
    ? RecursivePartial<U>[]
    : T[P] extends object
      ? RecursivePartial<T[P]>
      : T[P];
};

this way subobjects can also be partial but need to have the correct types if provided

RebeccaStevens commented 2 years ago

The Partial type is planned to be removed completely in the next version (whenever that may happen). A much more in-depth merging is planned.

See https://github.com/TehShrike/deepmerge/pull/226, specifically the types.ts file for more details. However, the typings there may be a little out of date now. See this alternative for the latest work on the typings (currently release as deepmerge-ts)