Skip to content

Commit 76a2ce1

Browse files
🤖 Merge PR DefinitelyTyped#46539 clone 2.1.2: Fixed missing parameters and overload. by @DG-za
* Fixed clone method missing parameters and overload. * Update types/clone/index.d.ts Co-authored-by: Piotr BÅ‚ażejewicz (Peter Blazejewicz) <[email protected]> * Update types/clone/index.d.ts Co-authored-by: Piotr BÅ‚ażejewicz (Peter Blazejewicz) <[email protected]> * Update index.d.ts Co-authored-by: Piotr BÅ‚ażejewicz (Peter Blazejewicz) <[email protected]>
1 parent 9ed156d commit 76a2ce1

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

‎types/clone/clone-tests.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
import clone = require('clone');
12

2-
import clone = require("clone");
3-
4-
var original = {
5-
key: "value"
3+
const original = {
4+
key: 'value',
65
};
76

8-
var copy = clone(original);
7+
let copy = clone(original);
8+
99
copy = clone(original, false);
1010
copy = clone(original, true, 1);
11+
copy = clone(original, true, 1, {});
12+
copy = clone(original, true, 1, {}, true);
13+
14+
copy = clone(original, {});
15+
copy = clone(original, { circular: false });
16+
copy = clone(original, { circular: true, depth: 1 });
17+
copy = clone(original, { circular: true, depth: 2, prototype: {} });
18+
copy = clone(original, { circular: true, depth: 3, prototype: {}, includeNonEnumerable: true });
19+
1120
copy = clone.clonePrototype(original);

‎types/clone/index.d.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Type definitions for clone 0.1.11
1+
// Type definitions for clone 2.1
22
// Project: https://github.com/pvorb/node-clone
3-
// Definitions by: Kieran Simpson <https://github.com/kierans/DefinitelyTyped>
3+
// Definitions by: Kieran Simpson <https://github.com/kierans>
4+
// DG-za <https://github.com/DG-za>
45
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
56

67
/**
@@ -10,9 +11,28 @@
1011
/**
1112
* @param val the value that you want to clone, any type allowed
1213
* @param circular Call clone with circular set to false if you are certain that obj contains no circular references. This will give better performance if needed. There is no error if undefined or null is passed as obj.
13-
* @param depth to wich the object is to be cloned (optional, defaults to infinity)
14+
* @param depth to which the object is to be cloned (optional, defaults to infinity)
15+
* @param prototype Sets the prototype to be used when cloning an Object (optional, defaults to __proto__)
16+
* @param includeNonEnumerable Set to true if the non-enumerable properties should be cloned as well (optional, defaults to false)
1417
*/
15-
declare function clone<T>(val: T, circular?: boolean, depth?: number): T;
18+
declare function clone<T>(val: T, circular?: boolean, depth?: number, prototype?: any, includeNonEnumerable?: boolean): T;
19+
20+
/**
21+
* @param val the value that you want to clone, any type allowed
22+
* @param opts a single object that specifies circular, depth, prototype and includeNonEnumerable.
23+
* @param opts.circular Call clone with circular set to false if you are certain that obj contains no circular references. This will give better performance if needed. There is no error if undefined or null is passed as obj.
24+
* @param opts.depth Sets depth to which the object is to be cloned (optional, defaults to infinity)
25+
* @param opts.prototype Sets the prototype to be used when cloning an Object (optional, defaults to __proto__)
26+
* @param opts.includeNonEnumerable Set to true if the non-enumerable properties should be cloned as well (optional, defaults to false)
27+
*/
28+
declare function clone<T>(val: T, opts: CloneOpts): T;
29+
30+
interface CloneOpts {
31+
circular?: boolean,
32+
depth?: number,
33+
prototype?: any,
34+
includeNonEnumerable?: boolean
35+
}
1636

1737
declare namespace clone {
1838
/**

0 commit comments

Comments
 (0)