From 3d572e1ee3e6492983ef01f8b7adf6150d345b11 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Tue, 8 Mar 2016 12:56:52 +0500 Subject: [PATCH] lodash: changed signatures of _.clone family methods --- lodash/lodash-3.10.d.ts | 478 ++++++++++++++++++++++++++++++++---- lodash/lodash-tests-3.10.ts | 329 +++++++++++++++++++------ lodash/lodash-tests.ts | 248 ++++++++++++++----- lodash/lodash.d.ts | 356 ++++++++++++++++++++------- 4 files changed, 1130 insertions(+), 281 deletions(-) diff --git a/lodash/lodash-3.10.d.ts b/lodash/lodash-3.10.d.ts index 5e96e2fdac..0f6e5a6e41 100644 --- a/lodash/lodash-3.10.d.ts +++ b/lodash/lodash-3.10.d.ts @@ -10124,132 +10124,516 @@ declare module _ { ********/ //_.clone + interface CloneCustomizer { + (value: TValue): TResult; + } + interface LoDashStatic { /** * Creates a clone of value. If isDeep is true nested objects are cloned, otherwise they are assigned by - * reference. 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. + * reference. 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 clone. * @param isDeep Specify a deep clone. * @param customizer The function to customize cloning values. * @param thisArg The this binding of customizer. * @return Returns the cloned value. */ - clone( + clone( + value: any, + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.clone + */ + clone( value: T, - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + + /** + * @see _.clone + */ + clone( + value: any, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.clone + */ + clone( + value: T, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; /** * @see _.clone */ clone( value: T, - customizer?: (value: any) => any, - thisArg?: any): T; + isDeep?: boolean + ): T; } interface LoDashImplicitWrapper { /** * @see _.clone */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): TResult; /** * @see _.clone */ clone( - customizer?: (value: any) => any, - thisArg?: any): T; + isDeep?: boolean + ): T; } interface LoDashImplicitArrayWrapper { /** * @see _.clone */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T[]; + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): TResult; /** * @see _.clone */ clone( - customizer?: (value: any) => any, - thisArg?: any): T[]; + isDeep?: boolean + ): T; } interface LoDashImplicitObjectWrapper { /** * @see _.clone */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): TResult; /** * @see _.clone */ clone( - customizer?: (value: any) => any, - thisArg?: any): T; + isDeep?: boolean + ): T; + } + + interface LoDashExplicitWrapper { + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + isDeep?: boolean + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + isDeep?: boolean + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + isDeep: boolean, + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.clone + */ + clone( + customizer: CloneCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.clone + */ + clone( + isDeep?: boolean + ): LoDashExplicitObjectWrapper; } //_.cloneDeep + interface CloneDeepCustomizer { + (value: TValue): TResult; + } + 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. + * 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 customizer The function to customize cloning values. * @param thisArg The this binding of customizer. * @return Returns the deep cloned value. */ - cloneDeep( + cloneDeep( + value: any, + customizer: CloneDeepCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.cloneDeep + */ + cloneDeep( value: T, - customizer?: (value: any) => any, - thisArg?: any): T; + customizer: CloneDeepCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.cloneDeep + */ + cloneDeep( + value: T + ): T; } interface LoDashImplicitWrapper { /** * @see _.cloneDeep */ - cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T; + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.cloneDeep + */ + cloneDeep(): T; } interface LoDashImplicitArrayWrapper { /** * @see _.cloneDeep */ - cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T[]; + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.cloneDeep + */ + cloneDeep(): T; } interface LoDashImplicitObjectWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): TResult; + + /** + * @see _.cloneDeep + */ + cloneDeep(): T; + } + + interface LoDashExplicitWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + /** * @see _.cloneDeep */ cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T; + isDeep?: boolean + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + isDeep?: boolean + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + customizer: CloneDeepCustomizer, + thisArg?: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.cloneDeep + */ + cloneDeep( + isDeep?: boolean + ): LoDashExplicitObjectWrapper; } //_.eq diff --git a/lodash/lodash-tests-3.10.ts b/lodash/lodash-tests-3.10.ts index 3399f71fea..857432083b 100644 --- a/lodash/lodash-tests-3.10.ts +++ b/lodash/lodash-tests-3.10.ts @@ -6313,87 +6313,260 @@ module TestWrap { ********/ // _.clone -interface TestCloneCustomizerFn { - (value: any): any; -} -var testCloneCustomizerFn: TestCloneCustomizerFn; -{ - let result: number; - result = _.clone(42); - result = _.clone(42, false); - result = _.clone(42, false, testCloneCustomizerFn); - result = _.clone(42, false, testCloneCustomizerFn, any); - result = _.clone(42, testCloneCustomizerFn); - result = _.clone(42, testCloneCustomizerFn, any); - result = _(42).clone(); - result = _(42).clone(false); - result = _(42).clone(false, testCloneCustomizerFn); - result = _(42).clone(false, testCloneCustomizerFn, any); - result = _(42).clone(testCloneCustomizerFn); - result = _(42).clone(testCloneCustomizerFn, any); -} -{ - let result: string[]; - result = _.clone([]); - result = _.clone([], false); - result = _.clone([], false, testCloneCustomizerFn); - result = _.clone([], false, testCloneCustomizerFn, any); - result = _.clone([], testCloneCustomizerFn); - result = _.clone([], testCloneCustomizerFn, any); - result = _([]).clone(); - result = _([]).clone(false); - result = _([]).clone(false, testCloneCustomizerFn); - result = _([]).clone(false, testCloneCustomizerFn, any); - result = _([]).clone(testCloneCustomizerFn); - result = _([]).clone(testCloneCustomizerFn, any); -} -{ - let result: {a: {b: number;}}; - result = _.clone<{a: {b: number;}}>({a: {b: 2}}); - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false); - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false, testCloneCustomizerFn); - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false, testCloneCustomizerFn, any); - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, testCloneCustomizerFn); - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, testCloneCustomizerFn, any); - result = _({a: {b: 2}}).clone(); - result = _({a: {b: 2}}).clone(false); - result = _({a: {b: 2}}).clone(false, testCloneCustomizerFn); - result = _({a: {b: 2}}).clone(false, testCloneCustomizerFn, any); - result = _({a: {b: 2}}).clone(testCloneCustomizerFn); - result = _({a: {b: 2}}).clone(testCloneCustomizerFn, any); +namespace TestClone { + interface CloneCustomizer { + (value: V): R; + } + + { + let customizer: CloneCustomizer; + let result: number; + + result = _.clone(42); + result = _.clone(42, false); + result = _(42).clone(); + result = _(42).clone(false); + } + + { + let customizer: CloneCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().clone(); + result = _(42).chain().clone(false); + } + + { + let customizer: CloneCustomizer; + let result: string; + + result = _.clone(42, false, customizer); + result = _.clone(42, false, customizer, any); + result = _.clone(42, customizer); + result = _.clone(42, customizer, any); + result = _.clone(42, false, customizer); + result = _.clone(42, false, customizer, any); + result = _.clone(42, customizer); + result = _.clone(42, customizer, any); + result = _(42).clone(false, customizer); + result = _(42).clone(false, customizer, any); + result = _(42).clone(customizer); + result = _(42).clone(customizer, any); + } + + { + let customizer: CloneCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().clone(false, customizer); + result = _(42).chain().clone(false, customizer, any); + result = _(42).chain().clone(customizer); + result = _(42).chain().clone(customizer, any); + } + + { + let customizer: CloneCustomizer; + let result: number[]; + + result = _.clone([42]); + result = _.clone([42], false); + result = _([42]).clone(); + result = _([42]).clone(false); + } + + { + let customizer: CloneCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().clone(); + result = _([42]).chain().clone(false); + } + + { + let customizer: CloneCustomizer; + let result: string[]; + + result = _.clone([42], false, customizer); + result = _.clone([42], false, customizer, any); + result = _.clone([42], customizer); + result = _.clone([42], customizer, any); + result = _.clone([42], false, customizer); + result = _.clone([42], false, customizer, any); + result = _.clone([42], customizer); + result = _.clone([42], customizer, any); + result = _([42]).clone(false, customizer); + result = _([42]).clone(false, customizer, any); + result = _([42]).clone(customizer); + result = _([42]).clone(customizer, any); + } + + { + let customizer: CloneCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().clone(false, customizer); + result = _([42]).chain().clone(false, customizer, any); + result = _([42]).chain().clone(customizer); + result = _([42]).chain().clone(customizer, any); + } + + { + let customizer: CloneCustomizer<{a: {b: string;};}, {a: {b: number;};}>; + let result: {a: {b: number;};}; + + result = _.clone({a: {b: 42}}); + result = _.clone({a: {b: 42}}, false); + result = _({a: {b: 42}}).clone(); + result = _({a: {b: 42}}).clone(false); + } + + { + let customizer: CloneCustomizer<{a: {b: string;};}, {a: {b: number;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: number;};}>; + + result = _({a: {b: 42}}).chain().clone(); + result = _({a: {b: 42}}).chain().clone(false); + } + + { + let customizer: CloneCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: {a: {b: string;};}; + + result = _.clone<{a: {b: number;};}>({a: {b: 42}}, false, customizer); + result = _.clone<{a: {b: number;};}>({a: {b: 42}}, false, customizer, any); + result = _.clone<{a: {b: number;};}>({a: {b: 42}}, customizer); + result = _.clone<{a: {b: number;};}>({a: {b: 42}}, customizer, any); + result = _.clone<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, false, customizer); + result = _.clone<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, false, customizer, any); + result = _.clone<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer); + result = _.clone<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer, any); + result = _({a: {b: 42}}).clone<{a: {b: number;};}>(false, customizer); + result = _({a: {b: 42}}).clone<{a: {b: number;};}>(false, customizer, any); + result = _({a: {b: 42}}).clone<{a: {b: number;};}>(customizer); + result = _({a: {b: 42}}).clone<{a: {b: number;};}>(customizer, any); + } + + { + let customizer: CloneCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: string;};}>; + + result = _({a: {b: 42}}).chain().clone<{a: {b: number;};}>(false, customizer); + result = _({a: {b: 42}}).chain().clone<{a: {b: number;};}>(false, customizer, any); + result = _({a: {b: 42}}).chain().clone<{a: {b: number;};}>(customizer); + result = _({a: {b: 42}}).chain().clone<{a: {b: number;};}>(customizer, any); + } } // _.cloneDeep -interface TestCloneDeepCustomizerFn { - (value: any): any; -} -var testCloneDeepCustomizerFn: TestCloneDeepCustomizerFn; -{ - let result: number; - result = _.cloneDeep(42); - result = _.cloneDeep(42, testCloneDeepCustomizerFn); - result = _.cloneDeep(42, testCloneDeepCustomizerFn, any); - result = _(42).cloneDeep(); - result = _(42).cloneDeep(testCloneDeepCustomizerFn); - result = _(42).cloneDeep(testCloneDeepCustomizerFn, any); -} -{ - let result: string[]; - result = _.cloneDeep([]); - result = _.cloneDeep([], testCloneDeepCustomizerFn); - result = _.cloneDeep([], testCloneDeepCustomizerFn, any); - result = _([]).cloneDeep(); - result = _([]).cloneDeep(testCloneDeepCustomizerFn); - result = _([]).cloneDeep(testCloneDeepCustomizerFn, any); -} -{ - let result: {a: {b: number;}}; - result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}); - result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepCustomizerFn); - result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepCustomizerFn, any); - result = _({a: {b: 2}}).cloneDeep(); - result = _({a: {b: 2}}).cloneDeep(testCloneDeepCustomizerFn); - result = _({a: {b: 2}}).cloneDeep(testCloneDeepCustomizerFn, any); +namespace TestCloneDeep { + interface CloneDeepCustomizer { + (value: V): R; + } + + { + let customizer: CloneDeepCustomizer; + let result: number; + + result = _.cloneDeep(42); + result = _(42).cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain.cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer; + let result: string; + + result = _.cloneDeep(42, customizer); + result = _.cloneDeep(42, customizer, any); + result = _.cloneDeep(42, customizer); + result = _.cloneDeep(42, customizer, any); + result = _(42).cloneDeep(customizer); + result = _(42).cloneDeep(customizer, any); + } + + { + let customizer: CloneDeepCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().cloneDeep(customizer); + result = _(42).chain().cloneDeep(customizer, any); + } + + { + let customizer: CloneDeepCustomizer; + let result: number[]; + + result = _.cloneDeep([42]); + result = _([42]).cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer; + let result: string[]; + + result = _.cloneDeep([42], customizer); + result = _.cloneDeep([42], customizer, any); + result = _.cloneDeep([42], customizer); + result = _.cloneDeep([42], customizer, any); + result = _([42]).cloneDeep(customizer); + result = _([42]).cloneDeep(customizer, any); + } + + { + let customizer: CloneDeepCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().cloneDeep(customizer); + result = _([42]).chain().cloneDeep(customizer, any); + } + + { + let customizer: CloneDeepCustomizer<{a: {b: string;};}, {a: {b: number;};}>; + let result: {a: {b: number;};}; + + result = _.cloneDeep({a: {b: 42}}); + result = _({a: {b: 42}}).cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer<{a: {b: string;};}, {a: {b: number;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: number;};}>; + + result = _({a: {b: 42}}).chain().cloneDeep(); + } + + { + let customizer: CloneDeepCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: {a: {b: string;};}; + + result = _.cloneDeep<{a: {b: number;};}>({a: {b: 42}}, customizer); + result = _.cloneDeep<{a: {b: number;};}>({a: {b: 42}}, customizer, any); + result = _.cloneDeep<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer); + result = _.cloneDeep<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer, any); + result = _({a: {b: 42}}).cloneDeep<{a: {b: number;};}>(customizer); + result = _({a: {b: 42}}).cloneDeep<{a: {b: number;};}>(customizer, any); + } + + { + let customizer: CloneDeepCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: string;};}>; + + result = _({a: {b: 42}}).chain().cloneDeep<{a: {b: number;};}>(customizer); + result = _({a: {b: 42}}).chain().cloneDeep<{a: {b: number;};}>(customizer, any); + } } // _.eq diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 3a857f0404..d2ab258f8e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -6036,79 +6036,197 @@ namespace TestCastArray { } // _.clone -{ - let result: number; - result = _.clone(42); - result = _(42).clone(); -} -{ - let result: string[]; - result = _.clone([]); - result = _([]).clone(); -} -{ - let result: {a: {b: number;}}; - result = _.clone<{a: {b: number;}}>({a: {b: 2}}); - result = _({a: {b: 2}}).clone(); +namespace TestClone { + { + let result: number; + + result = _.clone(42); + result = _(42).clone(); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().clone(); + } + + { + let result: string[]; + + result = _.clone(['']); + result = _(['']).clone(); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _(['']).chain().clone(); + } + + { + let result: {a: {b: number;};}; + + result = _.clone<{a: {b: number;};}>({a: {b: 42}}); + result = _({a: {b: 42}}).clone(); + } + + { + let result: _.LoDashExplicitObjectWrapper<{a: {b: number;};}>; + + result = _({a: {b: 42}}).chain().clone(); + } } // _.cloneDeep -{ - let result: number; - result = _.cloneDeep(42); - result = _(42).cloneDeep(); -} -{ - let result: string[]; - result = _.cloneDeep([]); - result = _([]).cloneDeep(); -} -{ - let result: {a: {b: number;}}; - result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}); - result = _({a: {b: 2}}).cloneDeep(); -} +namespace TestCloneDeep { + { + let result: number; -// _.cloneWith -interface TestCloneCustomizerFn { - (value: any): any; -} -var testCloneCustomizerFn: TestCloneCustomizerFn; -{ - let result: number; - result = _.clone(42, testCloneCustomizerFn); - result = _(42).clone(testCloneCustomizerFn); -} -{ - let result: string[]; - result = _.clone([], testCloneCustomizerFn); - result = _([]).clone(testCloneCustomizerFn); -} -{ - let result: {a: {b: number;}}; - result = _.clone<{a: {b: number;}}>({a: {b: 2}}, testCloneCustomizerFn); - result = _({a: {b: 2}}).clone(testCloneCustomizerFn); + result = _.cloneDeep(42); + result = _(42).cloneDeep(); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().cloneDeep(); + } + + { + let result: string[]; + + result = _.cloneDeep(['']); + result = _(['']).cloneDeep(); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _(['']).chain().cloneDeep(); + } + + { + let result: {a: {b: number;};}; + + result = _.cloneDeep<{a: {b: number;};}>({a: {b: 42}}); + result = _({a: {b: 42}}).cloneDeep(); + } + + { + let result: _.LoDashExplicitObjectWrapper<{a: {b: number;};}>; + + result = _({a: {b: 42}}).chain().cloneDeep(); + } } // _.cloneDeepWith -interface TestCloneDeepCustomizerFn { - (value: any): any; +namespace TestCloneDeepWith { + interface CloneDeepWithCustomizer { + (value: V): R; + } + + { + let customizer: CloneDeepWithCustomizer; + let reslut: string; + + result = _.cloneDeepWith(42, customizer); + result = _.cloneDeepWith(42, customizer); + result = _(42).cloneDeepWith(customizer); + } + + { + let customizer: CloneDeepWithCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().cloneDeepWith(customizer); + } + + { + let customizer: CloneDeepWithCustomizer; + let reslut: string[]; + + result = _.cloneDeepWith([42], customizer); + result = _.cloneDeepWith([42], customizer); + result = _([42]).cloneDeepWith(customizer); + } + + { + let customizer: CloneDeepWithCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().cloneDeepWith(customizer); + } + + { + let customizer: CloneDeepWithCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let reslut: {a: {b: string;};}; + + result = _.cloneDeepWith<{a: {b: string;};}>({a: {b: 42}}, customizer); + result = _.cloneDeepWith<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer); + result = _({a: {b: 42}}).cloneDeepWith<{a: {b: string;};}>(customizer); + } + + { + let customizer: CloneDeepWithCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: string;};}>; + + result = _({a: {b: 42}}).chain().cloneDeepWith<{a: {b: string;};}>(customizer); + } } -var testCloneDeepCustomizerFn: TestCloneDeepCustomizerFn; -{ - let result: number; - result = _.cloneDeep(42, testCloneDeepCustomizerFn); - result = _(42).cloneDeep(testCloneDeepCustomizerFn); -} -{ - let result: string[]; - result = _.cloneDeep([], testCloneDeepCustomizerFn); - result = _([]).cloneDeep(testCloneDeepCustomizerFn); -} -{ - let result: {a: {b: number;}}; - result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepCustomizerFn); - result = _({a: {b: 2}}).cloneDeep(testCloneDeepCustomizerFn); + +// _.cloneWith +namespace TestCloneWith { + interface CloneWithCustomizer { + (value: V): R; + } + + { + let customizer: CloneWithCustomizer; + let reslut: string; + + result = _.cloneWith(42, customizer); + result = _.cloneWith(42, customizer); + result = _(42).cloneWith(customizer); + } + + { + let customizer: CloneWithCustomizer; + let result: _.LoDashExplicitWrapper; + + result = _(42).chain().cloneWith(customizer); + } + + { + let customizer: CloneWithCustomizer; + let reslut: string[]; + + result = _.cloneWith([42], customizer); + result = _.cloneWith([42], customizer); + result = _([42]).cloneWith(customizer); + } + + { + let customizer: CloneWithCustomizer; + let result: _.LoDashExplicitArrayWrapper; + + result = _([42]).chain().cloneWith(customizer); + } + + { + let customizer: CloneWithCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let reslut: {a: {b: string;};}; + + result = _.cloneWith<{a: {b: string;};}>({a: {b: 42}}, customizer); + result = _.cloneWith<{a: {b: number;};}, {a: {b: string;};}>({a: {b: 42}}, customizer); + result = _({a: {b: 42}}).cloneWith<{a: {b: string;};}>(customizer); + } + + { + let customizer: CloneWithCustomizer<{a: {b: number;};}, {a: {b: string;};}>; + let result: _.LoDashExplicitObjectWrapper<{a: {b: string;};}>; + + result = _({a: {b: 42}}).chain().cloneWith<{a: {b: string;};}>(customizer); + } } // _.eq diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 9034976171..ca523aad8d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -10675,28 +10675,15 @@ declare module _ { //_.clone interface LoDashStatic { /** - * Creates a shallow clone of `value`. + * Creates a shallow clone of value. * - * **Note:** This method is loosely based on the - * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) - * and supports cloning arrays, array buffers, booleans, date objects, maps, - * numbers, `Object` objects, regexes, sets, strings, symbols, and typed - * arrays. The own enumerable properties of `arguments` objects are cloned - * as plain objects. An empty object is returned for uncloneable values such - * as error objects, functions, DOM nodes, and WeakMaps. + * Note: This method is loosely based on the structured clone algorithm and supports cloning arrays, + * array buffers, booleans, date objects, maps, numbers, Object objects, regexes, sets, strings, symbols, + * and typed arrays. The own enumerable properties of arguments objects are cloned as plain objects. An empty + * object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps. * - * @static - * @memberOf _ - * @category Lang - * @param {*} value The value to clone. - * @returns {*} Returns the cloned value. - * @example - * - * var objects = [{ 'a': 1 }, { 'b': 2 }]; - * - * var shallow = _.clone(objects); - * console.log(shallow[0] === objects[0]); - * // => true + * @param value The value to clone. + * @return Returns the cloned value. */ clone(value: T): T; } @@ -10723,23 +10710,35 @@ declare module _ { clone(): T; } + interface LoDashExplicitWrapper { + /** + * @see _.clone + */ + clone(): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + + /** + * @see _.clone + */ + clone(): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.clone + */ + clone(): LoDashExplicitObjectWrapper; + } + //_.cloneDeep interface LoDashStatic { /** - * This method is like `_.clone` except that it recursively clones `value`. + * This method is like _.clone except that it recursively clones value. * - * @static - * @memberOf _ - * @category Lang - * @param {*} value The value to recursively clone. - * @returns {*} Returns the deep cloned value. - * @example - * - * var objects = [{ 'a': 1 }, { 'b': 2 }]; - * - * var deep = _.cloneDeep(objects); - * console.log(deep[0] === objects[0]); - * // => false + * @param value The value to recursively clone. + * @return Returns the deep cloned value. */ cloneDeep(value: T): T; } @@ -10765,97 +10764,272 @@ declare module _ { cloneDeep(): T; } - //_.cloneWith - interface LoDashStatic { + interface LoDashExplicitWrapper { /** - * Creates a shallow clone of `value`. - * - * **Note:** This method is loosely based on the - * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) - * and supports cloning arrays, array buffers, booleans, date objects, maps, - * numbers, `Object` objects, regexes, sets, strings, symbols, and typed - * arrays. The own enumerable properties of `arguments` objects are cloned - * as plain objects. An empty object is returned for uncloneable values such - * as error objects, functions, DOM nodes, and WeakMaps. - * - * @static - * @memberOf _ - * @category Lang - * @param {*} value The value to clone. - * @returns {*} Returns the cloned value. - * @example - * - * var objects = [{ 'a': 1 }, { 'b': 2 }]; - * - * var shallow = _.clone(objects); - * console.log(shallow[0] === objects[0]); - * // => true + * @see _.cloneDeep */ - clone( - value: T, - customizer: (value: any) => any): T; + cloneDeep(): LoDashExplicitWrapper; } - interface LoDashImplicitWrapper { + interface LoDashExplicitArrayWrapper { /** - * @see _.clone + * @see _.cloneDeep */ - clone(customizer: (value: any) => any): T; + cloneDeep(): LoDashExplicitArrayWrapper; } - interface LoDashImplicitArrayWrapper { - + interface LoDashExplicitObjectWrapper { /** - * @see _.clone + * @see _.cloneDeep */ - clone(customizer: (value: any) => any): T[]; - } - - interface LoDashImplicitObjectWrapper { - /** - * @see _.clone - */ - clone(customizer: (value: any) => any): T; + cloneDeep(): LoDashExplicitObjectWrapper; } //_.cloneDeepWith + interface CloneDeepWithCustomizer { + (value: TValue): TResult; + } + 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 customizer The function to customize cloning values. - * @param thisArg The this binding of customizer. + * This method is like _.cloneWith except that it recursively clones value. + * + * @param value The value to recursively clone. + * @param customizer The function to customize cloning. * @return Returns the deep cloned value. */ - cloneDeep( + cloneDeepWith( + value: any, + customizer?: CloneDeepWithCustomizer + ): TResult; + + /** + * @see _.clonDeepeWith + */ + cloneDeepWith( value: T, - customizer: (value: any) => any): T; + customizer?: CloneDeepWithCustomizer + ): TResult; } interface LoDashImplicitWrapper { /** - * @see _.cloneDeep + * @see _.cloneDeepWith */ - cloneDeep(customizer: (value: any) => any): T; + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): TResult; } interface LoDashImplicitArrayWrapper { /** - * @see _.cloneDeep + * @see _.cloneDeepWith */ - cloneDeep(customizer: (value: any) => any): T[]; + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): TResult; } interface LoDashImplicitObjectWrapper { /** - * @see _.cloneDeep + * @see _.cloneDeepWith */ - cloneDeep(customizer: (value: any) => any): T; + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): TResult; + } + + interface LoDashExplicitWrapper { + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneDeepWith + */ + cloneDeepWith( + customizer?: CloneDeepWithCustomizer + ): LoDashExplicitObjectWrapper; + } + + //_.cloneWith + interface CloneWithCustomizer { + (value: TValue): TResult; + } + + interface LoDashStatic { + /** + * This method is like _.clone except that it accepts customizer which is invoked to produce the cloned value. + * If customizer returns undefined cloning is handled by the method instead. + * + * @param value The value to clone. + * @param customizer The function to customize cloning. + * @return Returns the cloned value. + */ + cloneWith( + value: any, + customizer?: CloneWithCustomizer + ): TResult; + + /** + * @see _.cloneWith + */ + cloneWith( + value: T, + customizer?: CloneWithCustomizer + ): TResult; + } + + interface LoDashImplicitWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): TResult; + } + + interface LoDashExplicitWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitArrayWrapper; + + /** + * @see _.cloneWith + */ + cloneWith( + customizer?: CloneWithCustomizer + ): LoDashExplicitObjectWrapper; } //_.eq