defu.d.ts 2.0 KB

123456789101112131415161718
  1. declare type Input = Record<string | number | symbol, any>;
  2. declare type Merger = <T extends Input, K extends keyof T>(obj: T, key: keyof T, value: T[K], namespace: string) => any;
  3. declare type MergeObjects<Destination extends Input, Defaults extends Input> = Destination extends Defaults ? Destination : Omit<Destination, keyof Destination & keyof Defaults> & Omit<Defaults, keyof Destination & keyof Defaults> & {
  4. -readonly [Key in keyof Destination & keyof Defaults]: Destination[Key] extends null ? Defaults[Key] extends null ? null : Defaults[Key] : Defaults[Key] extends null ? Destination[Key] : Merge<Destination[Key], Defaults[Key]>;
  5. };
  6. declare type DefuFn = <Source extends Input, Defaults extends Input>(source: Source, ...defaults: Defaults[]) => MergeObjects<Source, Defaults>;
  7. interface Defu {
  8. <Source extends Input, Defaults extends Input>(source: Source, ...defaults: Defaults[]): MergeObjects<Source, Defaults>;
  9. fn: DefuFn;
  10. arrayFn: DefuFn;
  11. extend(merger?: Merger): DefuFn;
  12. }
  13. declare type MergeArrays<Destination, Source> = Destination extends Array<infer DestinationType> ? Source extends Array<infer SourceType> ? Array<DestinationType | SourceType> : Source | Array<DestinationType> : Source | Destination;
  14. declare type Merge<Destination extends Input, Defaults extends Input> = Destination extends null ? Defaults extends null ? null : Defaults : Defaults extends null ? Destination : Destination extends Array<any> ? Defaults extends Array<any> ? MergeArrays<Destination, Defaults> : Destination | Defaults : Destination extends Function ? Destination | Defaults : Destination extends RegExp ? Destination | Defaults : Destination extends Promise<any> ? Destination | Defaults : Defaults extends Function ? Destination | Defaults : Defaults extends RegExp ? Destination | Defaults : Defaults extends Promise<any> ? Destination | Defaults : Destination extends Input ? Defaults extends Input ? MergeObjects<Destination, Defaults> : Destination | Defaults : Destination | Defaults;
  15. declare const defu: Defu;
  16. export default defu;