diff --git a/types/underscore/index.d.ts b/types/underscore/index.d.ts index c93f3de143..6e1118cde5 100644 --- a/types/underscore/index.d.ts +++ b/types/underscore/index.d.ts @@ -5100,7 +5100,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.map **/ - map(iterator: _.ListIterator, context?: any): _Chain; + map(iterator: _.ListIterator, context?: any): _Chain; /** * Wrapped type `any[]`. @@ -5112,7 +5112,7 @@ declare module _ { * Wrapped type `any[]`. * @see _.map **/ - map(iterator: _.ObjectIterator, context?: any): _Chain; + map(iterator: _.ObjectIterator, context?: any): _Chain; /** * @see _.map diff --git a/types/underscore/underscore-tests.ts b/types/underscore/underscore-tests.ts index d9a88adaa5..da01f4511f 100644 --- a/types/underscore/underscore-tests.ts +++ b/types/underscore/underscore-tests.ts @@ -209,6 +209,46 @@ _(stooges) .indexBy('age') .value()['40'].age; +let pensioners: string[] = _.chain(stooges) + .filter(p => p.age >= 60) + .map(p => p.name) + .value(); + +var usersData: _.Dictionary<{ age: number; name: string }> = { + 'user id': { name: 'moe', age: 40 }, + 'other user Id': { name: 'larry', age: 50 }, + 'fake id': { name: 'curly', age: 60 }, +}; + +let youngPeopleId: string[] = _.chain(usersData) + .map((p, k: string) => k) + .value(); + +let usersTable: { age: number; name: string; id: string }[] = _.chain(usersData) + .map<{ age: number; name: string; id: string }>((p, k: string) => { + return { id: k, ...p }; + }) + .value(); + +// Test map function with _ChainOfArrays<> +let usersTable_2 /*: { age: number; name: string; id: string }[][]*/ = _.chain(usersData) + .map<{ age: number; name: string; id: string }>((p, k: string) => { + return [{ id: k, ...p }]; + }) + .value(); + +let usersTable_3 /*: { score: number; fullName: string; login: string }[][]*/ = _.chain(usersTable) + .map<{ score: number; fullName: string; login: string }>(p => { + return [ + { + login: p.id, + fullName: p.name, + score: p.age, + }, + ]; + }) + .value(); + _.countBy([1, 2, 3, 4, 5], (num) => (num % 2 == 0) ? 'even' : 'odd'); _.shuffle([1, 2, 3, 4, 5, 6]);