Skip to content

Commit

Permalink
build: add type support for older TypeScript versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Stevens committed Nov 16, 2020
1 parent d21f41a commit b00128c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist/*
types/*
!types/legacy*
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions types/legacy/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<T1 extends object, T2 extends object>(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<T1 extends object, T2 extends object>(objects: [T1, T2], options?: Options): T1 & T2;
export function deepmergeAll<T1 extends object, T2 extends object, T3 extends object>(objects: [T1, T2, T3], options?: Options): T1 & T2 & T3;
export function deepmergeAll<T1 extends object, T2 extends object, T3 extends object, T4 extends object>(objects: [T1, T2, T3, T4], options?: Options): T1 & T2 & T3 & T4;
export function deepmergeAll<T1 extends object, T2 extends object, T3 extends object, T4 extends object, T5 extends object>(objects: [T1, T2, T3, T4, T5], options?: Options): T1 & T2 & T3 & T4 & T5;
export function deepmergeAll<T extends object>(objects: ReadonlyArray<T>, 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;
}

0 comments on commit b00128c

Please sign in to comment.