import { canMergeDeep } from '../common' ; export type Builtin = Function | Date | Error | RegExp | Uint8Array | string | number | boolean | bigint | symbol | undefined | null ; export type DeepMutation < T > = T extends Builtin ? T : T extends Array < infer U > ? Array < DeepMutation < U > > : T extends ReadonlyArray < infer U > ? ReadonlyArray < DeepMutation < U > > : T extends Record < any , any > ? { [ K in keyof Partial < T > ] : DeepMutation < T [ K ] > ; } : Partial < T > ; /**
 * A deep-merge strategy for mutations
 *
 * Deep-merges state and mutation recursively,
 * by enumerable keys (`for..in`),
 * so avoid recursive object links
 */ export const deep = < S extends Record < PropertyKey , any > > ( state ) => ( mutation ) => { for ( const key in mutation ) { state [ key as keyof S ] = canMergeDeep ( state , mutation , key ) ? deep ( state [ key ] ) ( mutation [ key ] ) : mutation [ key ] as S [ keyof S ] ; } return state ; } ;