[@types/underscore] Fix #36308 - underscore has bad chain typi… (#36510)

* [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319)

* [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319)
Add more test and applay changes form review

* [@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319)
 - Add more test
 - revert part of typings for function

* Comment part of test with currently didn't pass
This commit is contained in:
Radullus
2019-07-01 11:10:48 -07:00
committed by Ryan Cavanaugh
parent a59cd46314
commit 020e04aeb2
2 changed files with 42 additions and 2 deletions
+2 -2
View File
@@ -5100,7 +5100,7 @@ declare module _ {
* Wrapped type `any[]`.
* @see _.map
**/
map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): _Chain<TResult>;
map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): _Chain<TResult, TResult[]>;
/**
* Wrapped type `any[]`.
@@ -5112,7 +5112,7 @@ declare module _ {
* Wrapped type `any[]`.
* @see _.map
**/
map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): _Chain<TResult>;
map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): _Chain<TResult, TResult[]>;
/**
* @see _.map
+40
View File
@@ -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]);