forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[merge-deep] Add types (DefinitelyTyped#46907)
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Type definitions for merge-deep 3.0 | ||
// Project: https://github.com/jonschlinkert/merge-deep | ||
// Definitions by: Emily Marigold Klassen <https://github.com/forivall> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
export = mergeDeep; | ||
|
||
/** Recursively merge values in a javascript object. */ | ||
declare function mergeDeep<T, U>(orig: T, objects: U): T & U; | ||
declare function mergeDeep<T, U, V>(orig: T, objects1: U, objects2: V): T & U & V; | ||
declare function mergeDeep<T, U, V, W>(orig: T, objects1: U, objects2: V, objects3: W): T & U & V & W; | ||
declare function mergeDeep<T, U, V, W, X>(orig: T, objects1: U, objects2: V, objects3: W, objects4: X): T & U & V & W & X; | ||
declare function mergeDeep(target: any, ...sources: any[]): any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import merge = require('merge-deep'); | ||
|
||
merge({a: {b: {c: 'c', d: 'd'}}}, {a: {b: {e: 'e', f: 'f'}}}); | ||
|
||
const objectBase = { | ||
test: 'base' | ||
}; | ||
|
||
const objectOne = { | ||
test: 'one', | ||
iamone: true | ||
}; | ||
|
||
const objectTwo = { | ||
test: 2, | ||
iamtwo: true | ||
}; | ||
|
||
const objectThree = { | ||
iamthree: true, | ||
depth: { | ||
innerType: 'deep' | ||
} | ||
}; | ||
|
||
type ExtendedType = typeof objectBase & typeof objectOne; | ||
const extended: ExtendedType = merge(objectBase, objectOne); | ||
extended.test === 'one'; | ||
extended.iamone; | ||
|
||
type MoreExtendedType = typeof objectBase & typeof objectOne & typeof objectTwo; | ||
const moreExtended: MoreExtendedType = merge(objectBase, objectOne, objectTwo); | ||
moreExtended.test === 2; | ||
moreExtended.iamone; | ||
moreExtended.iamtwo; | ||
|
||
type DeepExtendedType = typeof objectBase & typeof objectOne & | ||
typeof objectTwo & typeof objectThree; | ||
const deepExtended: DeepExtendedType = merge(objectBase, objectOne, objectTwo, objectThree); | ||
deepExtended.iamone; | ||
deepExtended.iamtwo; | ||
deepExtended.iamthree; | ||
deepExtended.depth.innerType === 'deep'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"merge-deep-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |