Skip to content

Commit 001ca36

Browse files
committed
Merge pull request DefinitelyTyped#6582 from chrootsu/lodash-forEach
lodash: signatures of the method _.forEach have been changed
2 parents 1a2b789 + b3833f8 commit 001ca36

File tree

2 files changed

+372
-98
lines changed

2 files changed

+372
-98
lines changed

lodash/lodash-tests.ts

Lines changed: 186 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,101 @@ module TestDetect {
23062306
result = _(dictionary).detect<{a: number}, TResult>({a: 42});
23072307
}
23082308

2309+
// _.each
2310+
module TestEach {
2311+
let array: TResult[];
2312+
let list: _.List<TResult>;
2313+
let dictionary: _.Dictionary<TResult>;
2314+
2315+
let stringIterator: (char: string, index: number, string: string) => boolean|void;
2316+
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean|void;
2317+
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean|void;
2318+
2319+
{
2320+
let result: string;
2321+
2322+
_.each('', stringIterator);
2323+
_.each('', stringIterator, any);
2324+
}
2325+
2326+
{
2327+
let result: TResult[];
2328+
2329+
_.each<TResult>(array, listIterator);
2330+
_.each<TResult>(array, listIterator, any);
2331+
}
2332+
2333+
{
2334+
let result: _.List<TResult>;
2335+
2336+
_.each<TResult>(list, listIterator);
2337+
_.each<TResult>(list, listIterator, any);
2338+
}
2339+
2340+
{
2341+
let result: _.Dictionary<TResult>;
2342+
2343+
_.each<TResult>(dictionary, dictionaryIterator);
2344+
_.each<TResult>(dictionary, dictionaryIterator, any);
2345+
}
2346+
2347+
{
2348+
let result: _.LoDashImplicitWrapper<string>;
2349+
2350+
_('').each(stringIterator);
2351+
_('').each(stringIterator, any);
2352+
}
2353+
2354+
{
2355+
let result: _.LoDashImplicitArrayWrapper<TResult>;
2356+
2357+
_(array).each(listIterator);
2358+
_(array).each(listIterator, any);
2359+
}
2360+
2361+
{
2362+
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
2363+
2364+
_(list).each<TResult>(listIterator);
2365+
_(list).each<TResult>(listIterator, any);
2366+
}
2367+
2368+
{
2369+
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
2370+
2371+
_(dictionary).each<TResult>(dictionaryIterator);
2372+
_(dictionary).each<TResult>(dictionaryIterator, any);
2373+
}
2374+
2375+
{
2376+
let result: _.LoDashExplicitWrapper<string>;
2377+
2378+
_('').chain().each(stringIterator);
2379+
_('').chain().each(stringIterator, any);
2380+
}
2381+
2382+
{
2383+
let result: _.LoDashExplicitArrayWrapper<TResult>;
2384+
2385+
_(array).chain().each(listIterator);
2386+
_(array).chain().each(listIterator, any);
2387+
}
2388+
2389+
{
2390+
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
2391+
2392+
_(list).chain().each<TResult>(listIterator);
2393+
_(list).chain().each<TResult>(listIterator, any);
2394+
}
2395+
2396+
{
2397+
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
2398+
2399+
_(dictionary).chain().each<TResult>(dictionaryIterator);
2400+
_(dictionary).chain().each<TResult>(dictionaryIterator, any);
2401+
}
2402+
}
2403+
23092404
// _.every
23102405
module TestEvery {
23112406
let array: TResult[];
@@ -2461,19 +2556,100 @@ result = <number>_([1, 2, 3, 4]).findLast(function (num) {
24612556
result = <IFoodCombined>_(foodsCombined).findLast({ 'type': 'vegetable' });
24622557
result = <IFoodCombined>_(foodsCombined).findLast('organic');
24632558

2464-
result = <number[]>_.forEach([1, 2, 3], function (num) { console.log(num); });
2465-
result = <_.Dictionary<number>>_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
2466-
result = <IFoodType>_.forEach<IFoodType, string>({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
2559+
// _.forEach
2560+
module TestForEach {
2561+
let array: TResult[];
2562+
let list: _.List<TResult>;
2563+
let dictionary: _.Dictionary<TResult>;
2564+
2565+
let stringIterator: (char: string, index: number, string: string) => boolean|void;
2566+
let listIterator: (value: TResult, index: number, collection: _.List<TResult>) => boolean|void;
2567+
let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary<TResult>) => boolean|void;
2568+
2569+
{
2570+
let result: string;
2571+
2572+
_.forEach('', stringIterator);
2573+
_.forEach('', stringIterator, any);
2574+
}
2575+
2576+
{
2577+
let result: TResult[];
2578+
2579+
_.forEach<TResult>(array, listIterator);
2580+
_.forEach<TResult>(array, listIterator, any);
2581+
}
2582+
2583+
{
2584+
let result: _.List<TResult>;
2585+
2586+
_.forEach<TResult>(list, listIterator);
2587+
_.forEach<TResult>(list, listIterator, any);
2588+
}
2589+
2590+
{
2591+
let result: _.Dictionary<TResult>;
2592+
2593+
_.forEach<TResult>(dictionary, dictionaryIterator);
2594+
_.forEach<TResult>(dictionary, dictionaryIterator, any);
2595+
}
2596+
2597+
{
2598+
let result: _.LoDashImplicitWrapper<string>;
2599+
2600+
_('').forEach(stringIterator);
2601+
_('').forEach(stringIterator, any);
2602+
}
2603+
2604+
{
2605+
let result: _.LoDashImplicitArrayWrapper<TResult>;
24672606

2468-
result = <number[]>_.each([1, 2, 3], function (num) { console.log(num); });
2469-
result = <_.Dictionary<number>>_.each({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
2470-
result = <IFoodType>_.each<IFoodType, string>({ name: 'apple', type: 'fruit' }, function (value, key) { console.log(value, key) });
2607+
_(array).forEach(listIterator);
2608+
_(array).forEach(listIterator, any);
2609+
}
2610+
2611+
{
2612+
let result: _.LoDashImplicitObjectWrapper<_.List<TResult>>;
2613+
2614+
_(list).forEach<TResult>(listIterator);
2615+
_(list).forEach<TResult>(listIterator, any);
2616+
}
2617+
2618+
{
2619+
let result: _.LoDashImplicitObjectWrapper<_.Dictionary<TResult>>;
2620+
2621+
_(dictionary).forEach<TResult>(dictionaryIterator);
2622+
_(dictionary).forEach<TResult>(dictionaryIterator, any);
2623+
}
2624+
2625+
{
2626+
let result: _.LoDashExplicitWrapper<string>;
2627+
2628+
_('').chain().forEach(stringIterator);
2629+
_('').chain().forEach(stringIterator, any);
2630+
}
2631+
2632+
{
2633+
let result: _.LoDashExplicitArrayWrapper<TResult>;
2634+
2635+
_(array).chain().forEach(listIterator);
2636+
_(array).chain().forEach(listIterator, any);
2637+
}
2638+
2639+
{
2640+
let result: _.LoDashExplicitObjectWrapper<_.List<TResult>>;
2641+
2642+
_(list).chain().forEach<TResult>(listIterator);
2643+
_(list).chain().forEach<TResult>(listIterator, any);
2644+
}
24712645

2472-
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).forEach(function (num) { console.log(num); });
2473-
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).forEach(function (num) { console.log(num); });
2646+
{
2647+
let result: _.LoDashExplicitObjectWrapper<_.Dictionary<TResult>>;
24742648

2475-
result = <_.LoDashImplicitArrayWrapper<number>>_([1, 2, 3]).each(function (num) { console.log(num); });
2476-
result = <_.LoDashImplicitObjectWrapper<_.Dictionary<number>>>_(<{ [index: string]: number; }>{ 'one': 1, 'two': 2, 'three': 3 }).each(function (num) { console.log(num); });
2649+
_(dictionary).chain().forEach<TResult>(dictionaryIterator);
2650+
_(dictionary).chain().forEach<TResult>(dictionaryIterator, any);
2651+
}
2652+
}
24772653

24782654
result = <number[]>_.forEachRight([1, 2, 3], function (num) { console.log(num); });
24792655
result = <_.Dictionary<number>>_.forEachRight({ 'one': 1, 'two': 2, 'three': 3 }, function (num) { console.log(num); });
@@ -2851,18 +3027,10 @@ done = _.after(saves.length, function () {
28513027
console.log('Done saving!');
28523028
});
28533029

2854-
_.forEach(saves, function (type) {
2855-
asyncSave({ 'type': type, 'complete': done });
2856-
});
2857-
28583030
done = _(saves.length).after(function () {
28593031
console.log('Done saving!');
28603032
}).value();
28613033

2862-
_.forEach(saves, function (type) {
2863-
asyncSave({ 'type': type, 'complete': done });
2864-
});
2865-
28663034
// _.ary
28673035
result = <number[]>['6', '8', '10'].map(_.ary<(s: string) => number>(parseInt, 1));
28683036
result = <number[]>['6', '8', '10'].map(_(parseInt).ary<(s: string) => number>(1).value());

0 commit comments

Comments
 (0)