[@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319)#36510
[@types/underscore] Fix #36308 - underscore has bad chain typings fix only for function 'map' (#36319)#36510RyanCavanaugh merged 4 commits intoDefinitelyTyped:masterfrom Radullus:master
Conversation
… only for function 'map' (#36319)
|
@jgonggrijp @regevbr @renjfk Can you please review? |
|
@Radullus Thank you for submitting this PR! 🔔 @borisyankov @jbaldwin @ccurrens @confususs @jgonggrijp @ffflorian @regevbr - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place. If you have any questions or comments about me, you can ping |
|
I defer this one to @regevbr because he is currently working on a complete fix for the chain typings. I'm not sure whether the fix in the current PR will combine well with his work, but I think the unittest would be a welcome addition in any case. |
There was a problem hiding this comment.
@Radullus Thanks for the PR!
The T in _Chain<T,V> represents the type of the object and V represents the object.
So for example, string[] should be _Chain<string,string[]> and _.Dictionary<number> should be _Chain<number, _.Dictionary<number>
The lines you changed made your test pass, but they would cause other tests, that should be there but are not :), to fail.
Please see the following suggestion to fix the issue:
DefinitelyTyped/types/underscore/index.d.ts
Line 5103 in d200340
should be changed to
map<TResult>(iterator: _.ListIterator<T, TResult>, context?: any): _Chain<TResult, TResult[]>; DefinitelyTyped/types/underscore/index.d.ts
Line 5115 in d200340
should be changed to
map<TResult>(iterator: _.ObjectIterator<T, TResult>, context?: any): _Chain<TResult, _.Dictionary<TResult>>;Can you please try it (after reverting your change) and see if the test passes? Also I agree with @jgonggrijp that more tests are always welcome, so can you please also add a test for map operation on an object?
|
@Radullus One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you! |
… only for function 'map' (#36319) Add more test and applay changes form review
|
Hi @regevbr
|
types/underscore/index.d.ts
Outdated
| * @see _.map | ||
| **/ | ||
| map<TArray>(iterator: _.ListIterator<T, TArray[]>, context?: any): _ChainOfArrays<TArray>; | ||
| map<TArray>(iterator: _.ListIterator<T, TArray>, context?: any): _ChainOfArrays<TArray>; |
There was a problem hiding this comment.
this should be reverted as current behavior is ok
There was a problem hiding this comment.
done.
I have add test for this definition of 'map', but I have to comment part of the 'testing' witch check output because it will cause the test to fail.
types/underscore/index.d.ts
Outdated
| * @see _.map | ||
| **/ | ||
| map<TArray>(iterator: _.ObjectIterator<T, TArray[]>, context?: any): _ChainOfArrays<TArray>; | ||
| map<TArray>(iterator: _.ObjectIterator<T, TArray>, context?: any): _ChainOfArrays<TArray>; |
There was a problem hiding this comment.
this should be reverted as current behavior is ok
There was a problem hiding this comment.
done.
I have add test for this definition of 'map', but I have to comment part of the 'testing' witch check output because it will cause the test to fail.
| 'fake id': { name: 'curly', age: 60 }, | ||
| }; | ||
|
|
||
| let youngPeopleId: string[] = _.chain(usersData) |
There was a problem hiding this comment.
This test should actually fail, as performing filter on a a Dictionary returns T[], thus performing map on it will need the following iterator:
(value: T, index: number, list: T[]): TResult
The reason this test passes now is because of missing signature of filter for _Chain which should be:
filter(iterator: _.ObjectIterator<T, boolean>, context?: any): _Chain<T, T[]>;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
There was a problem hiding this comment.
You have right. I will stick in this test to 'map' function. I interface definition I was trying to test.
|
Thanks @Radullus! |
|
🔔 @regevbr - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
|
Updated numbers for you here from f3f7a2f: Comparison details 📊
It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place. |
… only for function 'map' (#36319) - Add more test - revert part of typings for function
|
Updated numbers for you here from c42c111: Comparison details 📊
It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place. |
| .value(); | ||
|
|
||
| // Test map function with _ChainOfArrays<> | ||
| let usersTable_2 /*: { age: number; name: string; id: string }[][]*/ = _.chain(usersData) |
There was a problem hiding this comment.
why did you remove the type here?
It is best to use the flatten() method here and then get the value
There was a problem hiding this comment.
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.
{ age: number; name: string; id: string }[][] // type return by underscore
{ age: number; name: string; id: string }[] // type with is calculate base of current definitions
It would require more changes in the underscore typescript definition. And I'm not certain what should be changed?
interface _ChainOfArrays<T> extends _Chain<T[]>
to
interface _ChainOfArrays<T> extends _Chain<T[], T[][]>
it will not match with data return from function 'groupBy'
There was a problem hiding this comment.
You are correct. Lets leave it be for now
| }) | ||
| .value(); | ||
|
|
||
| let usersTable_3 /*: { score: number; fullName: string; login: string }[][]*/ = _.chain(usersTable) |
There was a problem hiding this comment.
same here - why did you remove the type?
|
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
|
I just published |
…ain typi… (DefinitelyTyped#36510) * [@types/underscore] Fix DefinitelyTyped#36308 - underscore has bad chain typings fix only for function 'map' (DefinitelyTyped#36319) * [@types/underscore] Fix DefinitelyTyped#36308 - underscore has bad chain typings fix only for function 'map' (DefinitelyTyped#36319) Add more test and applay changes form review * [@types/underscore] Fix DefinitelyTyped#36308 - underscore has bad chain typings fix only for function 'map' (DefinitelyTyped#36319) - Add more test - revert part of typings for function * Comment part of test with currently didn't pass
Fix typing in 'underscore' for function 'map'
Please fill in this template.
Use a meaningful title for the pull request. Include the name of the package modified.
Test the change in your own code. (Compile and run.)
Add or edit tests to reflect the change. (Run with
npm test.)Follow the advice from the readme.
Avoid common mistakes.
Run
npm run lint package-name(ortscif notslint.jsonis present).Provide a URL to documentation or source code which provides context for the suggested changes: https://underscorejs.org/#map
https://underscorejs.org/#chain
Increase the version number in the header if appropriate.
If you are making substantial changes, consider adding a
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }.