Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add legacy type information #6

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };