-
Notifications
You must be signed in to change notification settings - Fork 30.6k
[@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319) #36510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0dbf774
c1db64c
d87f8e2
f197216
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you remove the type here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because the type by the underscore should be like this one in the comment, But with current typescript definition, There is missing one level of array nest.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct. Lets leave it be for now |
||
| .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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - why did you remove the type? |
||
| .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]); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should actually fail, as performing filter on a a Dictionary returns T[], thus performing map on it will need the following iterator:
The reason this test passes now is because of missing signature of filter for _Chain which should be:
But fixing it will not even help as the entire _Chain interface is malformed :-( and I'm working on a wide fix for it.
I would rather you only add tests that use the fixed map method
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have right. I will stick in this test to 'map' function. I interface definition I was trying to test.