diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c68e0f9e33..2cbec68537 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1091,6 +1091,42 @@ helloWrap2(); * Lang * ********/ +// _.cloneDeep +interface TestCloneDeepFn { + (value: any): any; +} +var testCloneDeepFn: TestCloneDeepFn; +result = _.cloneDeep(1); +result = _.cloneDeep(1, testCloneDeepFn); +result = _.cloneDeep(1, testCloneDeepFn, any); +result = _.cloneDeep('a'); +result = _.cloneDeep('a', testCloneDeepFn); +result = _.cloneDeep('a', testCloneDeepFn, any); +result = _.cloneDeep(true); +result = _.cloneDeep(true, testCloneDeepFn); +result = _.cloneDeep(true, testCloneDeepFn, any); +result = _.cloneDeep([1, 2]); +result = _.cloneDeep([1, 2], testCloneDeepFn); +result = _.cloneDeep([1, 2], testCloneDeepFn, any); +result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}); +result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn); +result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn, any); +result = _(1).cloneDeep(); +result = _(1).cloneDeep(testCloneDeepFn); +result = _(1).cloneDeep(testCloneDeepFn, any); +result = _('a').cloneDeep(); +result = _('a').cloneDeep(testCloneDeepFn); +result = _('a').cloneDeep(testCloneDeepFn, any); +result = _(true).cloneDeep(); +result = _(true).cloneDeep(testCloneDeepFn); +result = _(true).cloneDeep(testCloneDeepFn, any); +result = _([1, 2]).cloneDeep(); +result = _([1, 2]).cloneDeep(testCloneDeepFn); +result = _([1, 2]).cloneDeep(testCloneDeepFn, any); +result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(); +result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn); +result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn, any); + // _.gt result = _.gt(1, 2); result = _(1).gt(2); @@ -1232,11 +1268,6 @@ result = _.clone(stoogesAges, true, function (value) { return _.isElement(value) ? value.cloneNode(false) : undefined; }); -result = _.cloneDeep(stoogesAges); -result = _.cloneDeep(stoogesAges, function (value) { - return _.isElement(value) ? value.cloneNode(false) : undefined; -}); - interface Food { name: string; type: string; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index cbd83358c6..c088f54596 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -5997,6 +5997,53 @@ declare module _ { * Lang * ********/ + //_.cloneDeep + interface LoDashStatic { + /** + * Creates a deep clone of value. If customizer is provided it’s invoked to produce the cloned values. If + * customizer returns undefined cloning is handled by the method instead. The customizer is bound to thisArg + * and invoked with up to three argument; (value [, index|key, object]). + * Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments + * objects and objects created by constructors other than Object are cloned to plain Object objects. An empty + * object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps. + * @param value The value to deep clone. + * @param callback The function to customize cloning values. + * @param thisArg The this binding of customizer. + * @return Returns the deep cloned value. + */ + cloneDeep( + value: T, + callback?: (value: any) => any, + thisArg?: any): T; + } + + interface LoDashWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + callback?: (value: any) => any, + thisArg?: any): T; + } + + interface LoDashArrayWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + callback?: (value: any) => any, + thisArg?: any): T[]; + } + + interface LoDashObjectWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + callback?: (value: any) => any, + thisArg?: any): T; + } + //_.gt interface LoDashStatic { /** @@ -6469,28 +6516,6 @@ declare module _ { thisArg?: any): T; } - //_.cloneDeep - interface LoDashStatic { - /** - * Creates a deep clone of value. If a callback is provided it will be executed to produce the - * cloned values. If the callback returns undefined cloning will be handled by the method instead. - * The callback is bound to thisArg and invoked with one argument; (value). - * - * Note: This method is loosely based on the structured clone algorithm. Functions and DOM nodes - * are not cloned. The enumerable properties of arguments objects and objects created by constructors - * other than Object are cloned to plain Object objects. - * See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm. - * @param value The value to clone. - * @param callback The function to customize cloning values. - * @param thisArg The this binding of callback. - * @return The cloned value. - **/ - cloneDeep( - value: T, - callback?: (value: any) => any, - thisArg?: any): T; - } - //_.defaults interface LoDashStatic { /**