Skip to content

Commit

Permalink
fix: add legacy type information (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens authored Sep 16, 2021
1 parent 37d2e6c commit c7e1019
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 10 deletions.
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@
},
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"types": "types/current/index.d.ts",
"types": "types/legacy/v4_0.d.ts",
"typesVersions": {
"<4.1": {
"*": [
"types/legacy/v4_0.d.ts"
]
},
">=4.1": {
"*": [
"types/current/index.d.ts"
]
}
},
"files": [
"lib/",
"types/",
Expand Down Expand Up @@ -122,14 +134,6 @@
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
"peerDependencies": {
"typescript": ">=4.1.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
"engines": {
"node": ">=12.4.0"
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
},
"exclude": [
"benchmark/"
"benchmark/",
"types/"
]
}
75 changes: 75 additions & 0 deletions types/legacy/v4_0.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @file
*
* These types are a more simplified version of this library's types
* designed to work with versions of TypeScript < 4.1
*/

/**
* All the options the user can pass to customize deepmerge.
*/
declare type DeepMergeOptionsFull = Readonly<{
mergeRecords: DeepMergeMergeFunctions["mergeRecords"] | false;
mergeArrays: DeepMergeMergeFunctions["mergeArrays"] | false;
mergeMaps: DeepMergeMergeFunctions["mergeMaps"] | false;
mergeSets: DeepMergeMergeFunctions["mergeSets"] | false;
mergeOthers: DeepMergeMergeFunctions["mergeOthers"];
}>;

/**
* All the merge functions that deepmerge uses.
*/
declare type DeepMergeMergeFunctions = Readonly<{
mergeRecords: <Ts extends ReadonlyArray<Readonly<Record<keyof any, any>>>, U extends DeepMergeMergeFunctionUtils>(records: Ts, utils: U) => any;
mergeArrays: <Ts extends ReadonlyArray<Readonly<ReadonlyArray<any>>>, U extends DeepMergeMergeFunctionUtils>(records: Ts, utils: U) => any;
mergeMaps: <Ts extends ReadonlyArray<Readonly<ReadonlyMap<any, any>>>, U extends DeepMergeMergeFunctionUtils>(records: Ts, utils: U) => any;
mergeSets: <Ts extends ReadonlyArray<Readonly<ReadonlySet<any>>>, U extends DeepMergeMergeFunctionUtils>(records: Ts, utils: U) => any;
mergeOthers: <Ts extends ReadonlyArray<any>, U extends DeepMergeMergeFunctionUtils>(records: Ts, utils: U) => any;
}>;

/**
* The utils provided to the merge functions.
*/
declare type DeepMergeMergeFunctionUtils = Readonly<{
mergeFunctions: DeepMergeMergeFunctions;
defaultMergeFunctions: DeepMergeMergeFunctionsDefaults;
deepmerge: <Ts extends ReadonlyArray<any>>(...values: Ts) => any;
}>;

/**
* The default merge functions.
*/
declare type DeepMergeMergeFunctionsDefaults = Readonly<{
mergeMaps: (values: Record<keyof any, any>[], utils: DeepMergeMergeFunctionUtils) => any;
mergeSets: (values: any[][], utils: DeepMergeMergeFunctionUtils) => any;
mergeArrays: (values: Set<any>[], utils: DeepMergeMergeFunctionUtils) => any;
mergeRecords: (values: Map<any, any>[], utils: DeepMergeMergeFunctionUtils) => any;
mergeOthers: (values: any[], utils: DeepMergeMergeFunctionUtils) => any;
}>;

/**
* Deeply merge objects.
*
* @param objects - The objects to merge.
*/
declare function deepmerge(): undefined;
declare function deepmerge<T0>(arg0: T0): T0;
declare function deepmerge<T0, T1>(arg0: T0, arg1: T1): T0 & T1;
declare function deepmerge<T0, T1, T2>(arg0: T0, arg1: T1, arg2: T2): T0 & T1 & T2;
declare function deepmerge<T0, T1, T2, T3>(arg0: T0, arg1: T1, arg2: T2, arg3: T3): T0 & T1 & T2 & T3;
declare function deepmerge<T0, T1, T2, T3, T4>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4): T0 & T1 & T2 & T3 & T4;
declare function deepmerge<T0, T1, T2, T3, T4, T5>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): T0 & T1 & T2 & T3 & T4 & T5;
declare function deepmerge<T0, T1, T2, T3, T4, T5, T6>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6): T0 & T1 & T2 & T3 & T4 & T5 & T6;
declare function deepmerge<T0, T1, T2, T3, T4, T5, T6, T7>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7): T0 & T1 & T2 & T3 & T4 & T5 & T6 & T7;
declare function deepmerge<T0, T1, T2, T3, T4, T5, T6, T7, T8>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8): T0 & T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8;
declare function deepmerge<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(arg0: T0, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8, arg9: T9): T0 & T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9;
declare function deepmerge(...args: any[]): any;

/**
* Deeply merge two or more objects using the given options.
*
* @param options - The options on how to customize the merge function.
*/
declare function deepmergeCustom(options: Partial<DeepMergeOptionsFull>): (...objects: any[]) => any;

export { deepmerge, deepmergeCustom };

0 comments on commit c7e1019

Please sign in to comment.