From 73f06aed375723a5956dd31cfcc76114470118eb Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 16 Nov 2020 10:34:52 +1300 Subject: [PATCH] build: add type support for older TypeScript versions --- .gitignore | 1 + package.json | 7 ++++++- types/legacy/index.d.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 types/legacy/index.d.ts diff --git a/.gitignore b/.gitignore index 73a7d5e..fae2fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist/* types/* +!types/legacy* diff --git a/package.json b/package.json index 09f8db3..144fd3e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,11 @@ }, "license": "MIT", "main": "dist/cjs.js", - "types": "types/index.d.ts", + "types": "types/legacy/index.d.ts", + "typesVersions": { + "<4.1": { "*": ["types/legacy/*"] }, + ">=4.1": { "*": ["types/*"] } + }, "files": [ "/dist", "/types", @@ -30,6 +34,7 @@ "build": "npm run build:js && npm run build:types", "build:js": "rollup -c", "build:types": "tsc -p tsconfig.typedef.json", + "postbuild:types": "echo \"// Minimum TypeScript Version: 4.1\n\n$(cat types/index.d.ts)\" > types/index.d.ts", "presize": "npm run build:js", "size": "terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c", "pretest": "npm run build:js", diff --git a/types/legacy/index.d.ts b/types/legacy/index.d.ts new file mode 100644 index 0000000..ff85d32 --- /dev/null +++ b/types/legacy/index.d.ts @@ -0,0 +1,30 @@ +/** + * Deeply merge two objects. + * + * @param target The first object. + * @param source The second object. + * @param options Deep merge options. + */ +export default function deepmerge(target: T1, source: T2, options?: Options): T1 & T2; + +/** + * Deeply merge two or more objects. + * + * @param objects An tuple of the objects to merge. + * @param options Deep merge options. + */ +export function deepmergeAll(objects: [T1, T2], options?: Options): T1 & T2; +export function deepmergeAll(objects: [T1, T2, T3], options?: Options): T1 & T2 & T3; +export function deepmergeAll(objects: [T1, T2, T3, T4], options?: Options): T1 & T2 & T3 & T4; +export function deepmergeAll(objects: [T1, T2, T3, T4, T5], options?: Options): T1 & T2 & T3 & T4 & T5; +export function deepmergeAll(objects: ReadonlyArray, options?: Options): T; + +/** + * Deep merge options. + */ +export type Options = { + arrayMerge?: (target: object[], source: object[], options: Options) => any; + clone?: boolean; + customMerge?: (key: string) => ((target: object, source: object, options: Options) => any) | undefined; + isMergeable?: (value: object) => boolean; +}