From ff404a44c2ecf9169984f30d9e38adcc739992e6 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 15 Nov 2015 10:42:53 +0500 Subject: [PATCH] lodash: signatures of the method _.forOwn have been changed --- lodash/lodash-tests.ts | 51 ++++++++++++++++++++++++++++++++------- lodash/lodash.d.ts | 54 ++++++++++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 28 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 4c587b57b..44eb09f1b 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5275,20 +5275,55 @@ result = <_.LoDashImplicitObjectWrapper>_(new Dog('Dagny')).forInRight(func console.log(key); }); +// _.forOwn +module TestForOwn { + type SampleObject = {a: number; b: string; c: boolean;}; + + let dictionary: _.Dictionary; + let dictionaryIterator: (value: number, key: string, collection: _.Dictionary) => any; + + let object: SampleObject; + let objectIterator: (element: any, key?: string, collection?: any) => any; + + { + let result: _.Dictionary; + + result = _.forOwn(dictionary); + result = _.forOwn(dictionary, dictionaryIterator); + result = _.forOwn(dictionary, dictionaryIterator, any); + } + + { + let result: SampleObject; + + result = _.forOwn(object); + result = _.forOwn(object, objectIterator); + result = _.forOwn(object, objectIterator, any); + } + + { + let result: _.LoDashImplicitObjectWrapper<_.Dictionary>; + + result = _(dictionary).forOwn(); + result = _(dictionary).forOwn(dictionaryIterator); + result = _(dictionary).forOwn(dictionaryIterator, any); + } + + { + let result: _.LoDashExplicitObjectWrapper<_.Dictionary>; + + result = _(dictionary).chain().forOwn(); + result = _(dictionary).chain().forOwn(dictionaryIterator); + result = _(dictionary).chain().forOwn(dictionaryIterator, any); + } +} + interface ZeroOne { 0: string; 1: string; one: string; } -result = _.forOwn({ '0': 'zero', '1': 'one', 'one': '2' }, function (num, key) { - console.log(key); -}); - -result = <_.LoDashImplicitObjectWrapper>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function (num, key) { - console.log(key); -}); - result = _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) { console.log(key); }); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 98d8bf55d..b035ab0b3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -10003,35 +10003,49 @@ declare module _ { //_.forOwn interface LoDashStatic { /** - * Iterates over own enumerable properties of an object, executing the callback for each - * property. The callback is bound to thisArg and invoked with three arguments; (value, key, - * object). Callbacks may exit iteration early by explicitly returning false. - * @param object The object to iterate over. - * @param callback The function called per iteration. - * @param thisArg The this binding of callback. - * @return object - **/ - forOwn( + * Iterates over own enumerable properties of an object invoking iteratee for each property. The iteratee is + * bound to thisArg and invoked with three arguments: (value, key, object). Iteratee functions may exit + * iteration early by explicitly returning false. + * + * @param object The object to iterate over. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns object. + */ + forOwn( object: Dictionary, - callback?: DictionaryIterator, - thisArg?: any): Dictionary; + iteratee?: DictionaryIterator, + thisArg?: any + ): Dictionary; /** - * @see _.forOwn - **/ + * @see _.forOwn + */ forOwn( object: T, - callback?: ObjectIterator, - thisArg?: any): T; + iteratee?: ObjectIterator, + thisArg?: any + ): T; } interface LoDashImplicitObjectWrapper { /** - * @see _.forOwn - **/ - forOwn( - callback: ObjectIterator, - thisArg?: any): _.LoDashImplicitObjectWrapper; + * @see _.forOwn + */ + forOwn( + iteratee?: DictionaryIterator, + thisArg?: any + ): _.LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.forOwn + */ + forOwn( + iteratee?: DictionaryIterator, + thisArg?: any + ): _.LoDashExplicitObjectWrapper; } //_.forOwnRight