diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index a6b7b2cc16..63fd998701 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5552,87 +5552,79 @@ module TestWrap { ********/ // _.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(); +} + +// _.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(); +} + +// _.cloneWith 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); } -// _.cloneDeep +// _.cloneDeepWith 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); } // _.eq diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 1ba718812d..6f9f2f223b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -77,8 +77,8 @@ added 23 array methods: - [ ] _.xorWith added 18 lang methods: -- [ ] _.cloneDeepWith -- [ ] _.cloneWith +- [x] _.cloneDeepWith +- [x] _.cloneWith - [ ] _.eq - [ ] _.isArrayLike - [ ] _.isArrayLikeObject @@ -9099,87 +9099,150 @@ declare module _ { //_.clone 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. + * Creates a shallow clone of `value`. * - * @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. + * **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 */ - clone( - value: T, - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; - - /** - * @see _.clone - */ - clone( - value: T, - customizer?: (value: any) => any, - thisArg?: any): T; + clone(value: T): T; } interface LoDashImplicitWrapper { /** * @see _.clone */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; - - /** - * @see _.clone - */ - clone( - customizer?: (value: any) => any, - thisArg?: any): T; + clone(): T; } interface LoDashImplicitArrayWrapper { - /** - * @see _.clone - */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T[]; /** * @see _.clone */ - clone( - customizer?: (value: any) => any, - thisArg?: any): T[]; + clone(): T[]; } interface LoDashImplicitObjectWrapper { /** * @see _.clone */ - clone( - isDeep?: boolean, - customizer?: (value: any) => any, - thisArg?: any): T; + clone(): T; + } + + //_.cloneDeep + interface LoDashStatic { + /** + * 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 + */ + cloneDeep(value: T): T; + } + + interface LoDashImplicitWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep(): T; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep(): T[]; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.cloneDeep + */ + cloneDeep(): T; + } + + //_.cloneWith + interface LoDashStatic { + /** + * 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 + */ + clone( + value: T, + customizer: (value: any) => any): T; + } + + interface LoDashImplicitWrapper { + /** + * @see _.clone + */ + clone(customizer: (value: any) => any): T; + } + + interface LoDashImplicitArrayWrapper { /** * @see _.clone */ - clone( - customizer?: (value: any) => any, - thisArg?: any): T; + clone(customizer: (value: any) => any): T[]; } - //_.cloneDeep + interface LoDashImplicitObjectWrapper { + /** + * @see _.clone + */ + clone(customizer: (value: any) => any): T; + } + + //_.cloneDeepWith interface LoDashStatic { /** * Creates a deep clone of value. If customizer is provided it’s invoked to produce the cloned values. If @@ -9195,35 +9258,28 @@ declare module _ { */ cloneDeep( value: T, - customizer?: (value: any) => any, - thisArg?: any): T; + customizer: (value: any) => any): T; } interface LoDashImplicitWrapper { /** * @see _.cloneDeep */ - cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T; + cloneDeep(customizer: (value: any) => any): T; } interface LoDashImplicitArrayWrapper { /** * @see _.cloneDeep */ - cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T[]; + cloneDeep(customizer: (value: any) => any): T[]; } interface LoDashImplicitObjectWrapper { /** * @see _.cloneDeep */ - cloneDeep( - customizer?: (value: any) => any, - thisArg?: any): T; + cloneDeep(customizer: (value: any) => any): T; } //_.eq