From f9b7e0b5890bf3fabdb6da35c1f03c5a3b015a1b Mon Sep 17 00:00:00 2001 From: teppeis Date: Tue, 28 May 2019 23:31:48 +0900 Subject: [PATCH 1/3] fix type definition --- index.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7412fcf..a3569ce 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,4 @@ -declare function deepmerge(x: Partial, y: Partial, options?: deepmerge.Options): T; -declare function deepmerge(x: Partial, y: Partial, options?: deepmerge.Options): T1 & T2; +declare function deepmerge(x: T1, y: T2, options?: deepmerge.Options): T1 & T2; declare namespace deepmerge { export interface Options { @@ -10,7 +9,7 @@ declare namespace deepmerge { } export function all (objects: object[], options?: Options): object; - export function all (objects: Partial[], options?: Options): T; + export function all (objects: T[], options?: Options): T; } export = deepmerge; From c29cb5ee09d9f0c03374026f17861bcb1575f7bc Mon Sep 17 00:00:00 2001 From: teppeis Date: Thu, 30 May 2019 08:28:47 +0900 Subject: [PATCH 2/3] fix type definition of deepmerge.all() and add tests --- index.d.ts | 5 ++- test/typescript.ts | 78 +++++++++++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/index.d.ts b/index.d.ts index a3569ce..39ce5b9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,7 +8,10 @@ declare namespace deepmerge { isMergeableObject?(value: object): boolean; } - export function all (objects: object[], options?: Options): object; + export function all (objects: [T1, T2], options?: Options): T1 & T2; + export function all (objects: [T1, T2, T3], options?: Options): T1 & T2 & T3; + export function all (objects: [T1, T2, T3, T4], options?: Options): T1 & T2 & T3 & T4; + export function all (objects: [T1, T2, T3, T4, T5], options?: Options): T1 & T2 & T3 & T4 & T5; export function all (objects: T[], options?: Options): T; } diff --git a/test/typescript.ts b/test/typescript.ts index 23d2c5c..ab3817d 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -1,33 +1,63 @@ import * as merge from '../'; -const x = { - foo: 'abc', - bar: 'def', - wat: 42, +let x: { + foo: string, + bar: string, } -const y = { - foo: 'cba', - bar: 'fed', - wat: 42, +let y: { + foo: string, + baz: string, + wat: string, } -const z = { - baz: '123', - quux: '456', - wat: 42, +let z: { + bar: string, + baz: string, + qux?: string, } -let merged1 = merge(x, y); -let merged2 = merge(x, z); -let merged3 = merge.all<{wat: number}>([ x, y, z ]); +let merged1: {foo: string, bar: string, baz: string, wat: string} = merge(x, y); +let merged2: {foo: string, bar: string, baz: string, qux?: string} = merge(x, z); -merged1.foo; -merged1.bar; -merged2.foo; -merged2.baz; -merged3.wat; +let mergedAll1: {t1: string} = merge.all([ + {t1: 'a'}, +]) +let mergedAll2: {t1: string, t2: string} = merge.all([ + {t1: 'a'}, + {t2: 'a'}, +]) + +let mergedAll3: {t1: string, t2: string, t3: string} = merge.all([ + {t1: 'a'}, + {t2: 'a'}, + {t3: 'a'}, +]) + +let mergedAll4: {t1: string, t2: string, t3: string, t4: string} = merge.all([ + {t1: 'a'}, + {t2: 'a'}, + {t3: 'a'}, + {t4: 'a'}, +]) + +let mergedAll5: {t1: string, t2: string, t3: string, t4: string, t5: string} = merge.all([ + {t1: 'a'}, + {t2: 'a'}, + {t3: 'a'}, + {t4: 'a'}, + {t5: 'a'}, +]) + +let merged6: {t1: string} = merge.all([ + {t1: 'a'}, + {t1: 'a'}, + {t1: 'a'}, + {t1: 'a'}, + {t1: 'a'}, + {t1: 'a'}, +]) const options1: merge.Options = { clone: true, @@ -60,6 +90,10 @@ const options3: merge.Options = { merged1 = merge(x, y, options1); merged2 = merge(x, z, options2); -merged3 = merge.all<{wat: number}>([x, y, z], options1); +mergedAll3 = merge.all([ + {t1: 'a'}, + {t2: 'a'}, + {t3: 'a'}, +], options1) -const merged4 = merge(x, y, options3); +merged1 = merge(x, y, options3); From 6dfcb006f540ab404d7d05fd11541d2f8a6c074e Mon Sep 17 00:00:00 2001 From: teppeis Date: Thu, 30 May 2019 08:37:54 +0900 Subject: [PATCH 3/3] fix typescript.ts for ts-node test --- test/typescript.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/typescript.ts b/test/typescript.ts index ab3817d..2ceafdf 100644 --- a/test/typescript.ts +++ b/test/typescript.ts @@ -1,23 +1,26 @@ import * as merge from '../'; -let x: { - foo: string, - bar: string, +let x = { + foo: 'abc', + bar: 'def', } -let y: { - foo: string, - baz: string, - wat: string, +let y = { + foo: 'cba', + baz: 'fed', + wat: 42, } let z: { bar: string, baz: string, qux?: string, +} = { + bar: 'a', + baz: 'a' } -let merged1: {foo: string, bar: string, baz: string, wat: string} = merge(x, y); +let merged1: {foo: string, bar: string, baz: string, wat: number} = merge(x, y); let merged2: {foo: string, bar: string, baz: string, qux?: string} = merge(x, z); let mergedAll1: {t1: string} = merge.all([