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 type definition by removing Partial #148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
declare function deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T;
declare function deepmerge<T1, T2>(x: Partial<T1>, y: Partial<T2>, options?: deepmerge.Options): T1 & T2;
declare function deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2;

declare namespace deepmerge {
export interface Options {
Expand All @@ -9,8 +8,11 @@ declare namespace deepmerge {
isMergeableObject?(value: object): boolean;
}

export function all (objects: object[], options?: Options): object;
export function all<T> (objects: Partial<T>[], options?: Options): T;
export function all<T1, T2> (objects: [T1, T2], options?: Options): T1 & T2;
export function all<T1, T2, T3> (objects: [T1, T2, T3], options?: Options): T1 & T2 & T3;
export function all<T1, T2, T3, T4> (objects: [T1, T2, T3, T4], options?: Options): T1 & T2 & T3 & T4;
export function all<T1, T2, T3, T4, T5> (objects: [T1, T2, T3, T4, T5], options?: Options): T1 & T2 & T3 & T4 & T5;
export function all<T> (objects: T[], options?: Options): T;
}

export = deepmerge;
73 changes: 55 additions & 18 deletions test/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,66 @@
import * as merge from '../';

const x = {
let x = {
foo: 'abc',
bar: 'def',
wat: 42,
}

const y = {
let y = {
foo: 'cba',
bar: 'fed',
baz: 'fed',
wat: 42,
}

const z = {
baz: '123',
quux: '456',
wat: 42,
let z: {
bar: string,
baz: string,
qux?: string,
} = {
bar: 'a',
baz: 'a'
}

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: number} = merge(x, y);
let merged2: {foo: string, bar: string, baz: string, qux?: string} = merge(x, z);

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'},
])

merged1.foo;
merged1.bar;
merged2.foo;
merged2.baz;
merged3.wat;
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,
Expand Down Expand Up @@ -60,6 +93,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);