[@types/underscore] Collection and Array Tests - Reduce and ReduceRight#45893
Conversation
|
@reubenrybnik Thank you for submitting this PR! This is a live comment which I will keep updated. Code ReviewsBecause you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 45893,
"author": "reubenrybnik",
"owners": [
"borisyankov",
"jbaldwin",
"ccurrens",
"confususs",
"jgonggrijp",
"ffflorian",
"regevbr",
"peterblazejewicz",
"reubenrybnik"
],
"dangerLevel": "ScopedAndTested",
"headCommitAbbrOid": "d952cf3",
"headCommitOid": "d952cf3c9669bd2a1b39f465bc3edc514d545609",
"mergeIsRequested": true,
"stalenessInDays": 0,
"lastCommitDate": "2020-07-07T16:00:53.000Z",
"lastCommentDate": "2020-07-07T21:57:41.000Z",
"maintainerBlessed": false,
"reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45893/files",
"hasMergeConflict": false,
"authorIsOwner": true,
"isFirstContribution": false,
"popularityLevel": "Popular",
"anyPackageIsNew": false,
"packages": [
"underscore"
],
"files": [
{
"filePath": "types/underscore/index.d.ts",
"kind": "definition",
"package": "underscore"
},
{
"filePath": "types/underscore/underscore-tests.ts",
"kind": "test",
"package": "underscore"
}
],
"hasDismissedReview": false,
"ciResult": "pass",
"lastReviewDate": "2020-07-07T18:47:35.000Z",
"reviewersWithStaleReviews": [],
"approvalFlags": 2,
"isChangesRequested": false
} |
|
🔔 @borisyankov @jbaldwin @ccurrens @confususs @jgonggrijp @ffflorian @regevbr @peterblazejewicz - please review this PR in the next few days. Be sure to explicitly select |
|
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
jgonggrijp
left a comment
There was a problem hiding this comment.
Good work, and indeed simpler than the previous PR. The semantics of reduce-without-initial-memo are a bit different, though. See comments below.
|
@reubenrybnik 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. If you disagree with the reviewer's comments, you can "dismiss" the review using GitHub's review UI. Thank you! |
…ifferent result type to be specified or inferred, adding undefined to the posible result of reduce calls, and adding tests around union-type results.
|
@jgonggrijp Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
…result can be specified when calling reduce with no memo.
…al memo to take no memo since a memo that is explicitly provided as undefined will still be treated as the memo value to use instead of using the first item in the collection..
… memo since the result in such cases is the memo.
|
Alright @jgonggrijp, I think I've got all the feedback here addressed whenever you're ready to take another look. Thanks for catching the explicit undefined memo issue and incorrect undefined return type when a memo is provided, I appreciate it! Sorry for not doing a better job of making sure I had a good understanding of these special cases this time around. |
jgonggrijp
left a comment
There was a problem hiding this comment.
No need to apologize!
I'm still a bit confused by some of your comments, but the code looks good to me, so I guess this is a go. 👍
|
Thanks @jgonggrijp, you definitely saved me from doing some incorrect things in this one. It took longer than it should have for me to get that an explicitly undefined memo didn't work like I expected it to and I had for a while erroneously thought that you were asking me to collapse the overloads for handling the different memo cases back down to a single overload with an optional memo, which is probably why some of my comments seemed somewhat off the mark. Plugging the final result into my company's solution, I end up with one new error because the result of a memoless call now also includes |
I agree, although you could try to prevent it by adding an even more specialized overload for memoless calls with an empty collection. It depends on how far you want to go; I'm fine with it either way. |
I did spend a bit of time thinking about this, but while TS does have the concept of an empty array type I think the more interesting overload to add here would be one that drops undefined when TS knows it doesn't have an empty array, which I guess would be represented by the type |
|
It looks like there's some discussion happening around such a type guard in microsoft/TypeScript#28837, so maybe at some point in the future it'll be more practical to add an overload like this. I can't think of any equivalent for dictionaries, though, so I think dictionaries are probably likely to forever go without. |
|
Ready to merge |
…rray Tests - Reduce and ReduceRight by @reubenrybnik * Updating type definitions for reduce and reduceRight and adding tests. * Adding defaults for V in memo iterators. * Updating a few tests to test constant memos more and omitted memos less. * Updating reduce and reduceRight undefined memo overloads to allow a different result type to be specified or inferred, adding undefined to the posible result of reduce calls, and adding tests around union-type results. * Making a few test changes to better illustrate the ways that a union result can be specified when calling reduce with no memo. * Rewriting the overloads of reduce and reduceRight that take an optional memo to take no memo since a memo that is explicitly provided as undefined will still be treated as the memo value to use instead of using the first item in the collection.. * Removing the undefined type from the result for overloads that take a memo since the result in such cases is the memo. * Breaking up tests for multiple aliases by alias.
…rray Tests - Reduce and ReduceRight by @reubenrybnik * Updating type definitions for reduce and reduceRight and adding tests. * Adding defaults for V in memo iterators. * Updating a few tests to test constant memos more and omitted memos less. * Updating reduce and reduceRight undefined memo overloads to allow a different result type to be specified or inferred, adding undefined to the posible result of reduce calls, and adding tests around union-type results. * Making a few test changes to better illustrate the ways that a union result can be specified when calling reduce with no memo. * Rewriting the overloads of reduce and reduceRight that take an optional memo to take no memo since a memo that is explicitly provided as undefined will still be treated as the memo value to use instead of using the first item in the collection.. * Removing the undefined type from the result for overloads that take a memo since the result in such cases is the memo. * Breaking up tests for multiple aliases by alias.
npm test.)npm run lint package-name(ortscif notslint.jsonis present).This PR continues the planned set that will together add up to #45201 and includes the following changes:
reduceandreduceRight.reduceandreduceRightinto separate overloads for omitting and specifying a memo where the former forces the result type to include both the item type of the collection and undefined.Underscoreand_Chainversions ofreduceandreduceRightto work with both Lists and Dictionaries to partially fix Underscore collections functions should take objects #20623.