mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
* [@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:
Vendored
+2
-2
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user