lodash: signatures of the method _.forOwn have been changed

This commit is contained in:
Ilya Mochalov
2015-11-15 10:42:53 +05:00
parent aed176536a
commit ff404a44c2
2 changed files with 77 additions and 28 deletions
+43 -8
View File
@@ -5275,20 +5275,55 @@ result = <_.LoDashImplicitObjectWrapper<Dog>>_(new Dog('Dagny')).forInRight(func
console.log(key);
});
// _.forOwn
module TestForOwn {
type SampleObject = {a: number; b: string; c: boolean;};
let dictionary: _.Dictionary<number>;
let dictionaryIterator: (value: number, key: string, collection: _.Dictionary<number>) => any;
let object: SampleObject;
let objectIterator: (element: any, key?: string, collection?: any) => any;
{
let result: _.Dictionary<number>;
result = _.forOwn<number>(dictionary);
result = _.forOwn<number>(dictionary, dictionaryIterator);
result = _.forOwn<number>(dictionary, dictionaryIterator, any);
}
{
let result: SampleObject;
result = _.forOwn<SampleObject>(object);
result = _.forOwn<SampleObject>(object, objectIterator);
result = _.forOwn<SampleObject>(object, objectIterator, any);
}
{
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<number>>;
result = _(dictionary).forOwn<number>();
result = _(dictionary).forOwn<number>(dictionaryIterator);
result = _(dictionary).forOwn<number>(dictionaryIterator, any);
}
{
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<number>>;
result = _(dictionary).chain().forOwn<number>();
result = _(dictionary).chain().forOwn<number>(dictionaryIterator);
result = _(dictionary).chain().forOwn<number>(dictionaryIterator, any);
}
}
interface ZeroOne {
0: string;
1: string;
one: string;
}
result = <ZeroOne>_.forOwn(<ZeroOne>{ '0': 'zero', '1': 'one', 'one': '2' }, function (num, key) {
console.log(key);
});
result = <_.LoDashImplicitObjectWrapper<ZeroOne>>_({ '0': 'zero', '1': 'one', 'length': 2 }).forOwn(function (num, key) {
console.log(key);
});
result = <any>_.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function (num, key) {
console.log(key);
});
+34 -20
View File
@@ -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<T extends {}>(
* 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<T>(
object: Dictionary<T>,
callback?: DictionaryIterator<T, void>,
thisArg?: any): Dictionary<T>;
iteratee?: DictionaryIterator<T, any>,
thisArg?: any
): Dictionary<T>;
/**
* @see _.forOwn
**/
* @see _.forOwn
*/
forOwn<T extends {}>(
object: T,
callback?: ObjectIterator<any, void>,
thisArg?: any): T;
iteratee?: ObjectIterator<any, any>,
thisArg?: any
): T;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.forOwn
**/
forOwn<T extends {}>(
callback: ObjectIterator<T, void>,
thisArg?: any): _.LoDashImplicitObjectWrapper<T>;
* @see _.forOwn
*/
forOwn<TValue>(
iteratee?: DictionaryIterator<TValue, any>,
thisArg?: any
): _.LoDashImplicitObjectWrapper<T>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.forOwn
*/
forOwn<TValue>(
iteratee?: DictionaryIterator<TValue, any>,
thisArg?: any
): _.LoDashExplicitObjectWrapper<T>;
}
//_.forOwnRight