Skip to content

[@types/underscore] Collection and Array Tests - Max, Min, and Size#46240

Merged
typescript-bot merged 2 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-max-min-size
Jul 25, 2020
Merged

[@types/underscore] Collection and Array Tests - Max, Min, and Size#46240
typescript-bot merged 2 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-max-min-size

Conversation

@reubenrybnik
Copy link
Copy Markdown
Contributor

@reubenrybnik reubenrybnik commented Jul 21, 2020

  • 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 (or tsc if no tslint.json is present).
  • Provide a URL to documentation or source code which provides context for the suggested changes: https://underscorejs.org/
  • Include tests for your changes

This PR continues the planned set that will together add up to #45201 and includes the following changes:

  • Adds tests for min, max, and size.
  • Collapses overloads of min and max by updating them to use Iteratee.
  • Updates the return values of max and min to always include number to cover the possibilities of +/-Infinity for empty collections.
  • Drops the unnecessary T generic from UnderscoreStatic.size.
  • Updates the Underscore and _Chain versions of max and min to work with both Lists and Dictionaries to partially fix Underscore collections functions should take objects #20623.

@typescript-bot typescript-bot added Where is GH Actions? GH Actions didn't give a response to this PR Popular package This PR affects a popular package (as counted by NPM download counts). Author is Owner The author of this PR is a listed owner of the package. labels Jul 21, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Jul 21, 2020

@reubenrybnik Thank you for submitting this PR!

This is a live comment which I will keep updated.

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

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": 46240,
  "author": "reubenrybnik",
  "owners": [
    "borisyankov",
    "jbaldwin",
    "ccurrens",
    "confususs",
    "jgonggrijp",
    "ffflorian",
    "regevbr",
    "peterblazejewicz",
    "reubenrybnik"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "ee9bd2d",
  "headCommitOid": "ee9bd2d6b6bd40ee9d75658cf2e05f7a055b4e8a",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastPushDate": "2020-07-25T02:24:19.000Z",
  "lastCommentDate": "2020-07-25T22:25:09.000Z",
  "maintainerBlessed": false,
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46240/files",
  "hasMergeConflict": false,
  "authorIsOwner": true,
  "isFirstContribution": false,
  "popularityLevel": "Popular",
  "anyPackageIsNew": false,
  "packages": [
    "underscore"
  ],
  "files": [
    {
      "path": "types/underscore/index.d.ts",
      "kind": "definition",
      "package": "underscore"
    },
    {
      "path": "types/underscore/underscore-tests.ts",
      "kind": "test",
      "package": "underscore"
    }
  ],
  "hasDismissedReview": false,
  "ciResult": "pass",
  "lastReviewDate": "2020-07-25T20:40:00.000Z",
  "reviewersWithStaleReviews": [],
  "approvalFlags": 2,
  "isChangesRequested": false
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @borisyankov @jbaldwin @ccurrens @confususs @jgonggrijp @ffflorian @regevbr @peterblazejewicz — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot removed the Where is GH Actions? GH Actions didn't give a response to this PR label Jul 21, 2020
@reubenrybnik
Copy link
Copy Markdown
Contributor Author

My company's solution does unfortunately end up with several new errors due to number now being included in all results for max and min calls, but I feel like that's as accurate as find potentially returning undefined so I'd still like to keep it (though admittedly the ! operator doesn't help here like it does in the find case).

@typescript-bot
Copy link
Copy Markdown
Contributor

👋 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 📊
master #46240 diff
Batch compilation
Memory usage (MiB) 66.7 57.8 -13.3%
Type count 11533 12008 +4%
Assignability cache size 1382 1450 +5%
Language service
Samples taken 6355 6703 +5%
Identifiers in tests 6355 6703 +5%
getCompletionsAtPosition
    Mean duration (ms) 193.0 195.7 +1.4%
    Mean CV 8.5% 7.9%
    Worst duration (ms) 373.0 365.4 -2.0%
    Worst identifier stringMemo resultUnionPartialMemoIterator
getQuickInfoAtPosition
    Mean duration (ms) 187.8 190.9 +1.6%
    Mean CV 8.6% 8.2% -4.6%
    Worst duration (ms) 388.7 394.2 +1.4%
    Worst identifier _ _

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Jul 22, 2020
Copy link
Copy Markdown
Contributor

@jgonggrijp jgonggrijp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types could be more accurate by exploiting IterateeResult. That said, they are already more accurate than they were and I'd consider this good enough. It's also great to get rid of such a verbose bunch of overloads again.

So I'm suggesting changes, but I'm also fine with it if you want to leave it at this.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Jul 24, 2020
…mbers since several other types can be comparable in ways that work with these functions.
@typescript-bot typescript-bot removed Self Merge This PR can now be self-merged by the PR author or an owner Owner Approved A listed owner of this package signed off on the pull request. labels Jul 25, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@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?

Copy link
Copy Markdown
Contributor

@jgonggrijp jgonggrijp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the latest change is an improvement.

Regarding the problems with the sophisticated type I suggested, I think the principle is still sound, but I defined NumberComparable too narrowly. The JS runtime will try very hard to coerce the operand; if valueOf results in a string instead of a number, then that string will be coerced to number after all (even though that results in NaN in many cases). So it will probably work better if you change it accordingly:

type NumberComparable = {
    valueOf(): number | string | boolean | null | undefined;
} | {
    [Symbol.toPrimitive](): number | string | boolean | null | undefined;
} | {
    toString(): string;
};

But I have no objection against leaving it as is.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Jul 25, 2020
@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Thanks @jgonggrijp! I'm a little worried at this point that this may be a potential maintenance headache due to possible future additional implementations that might make an object comparable along with this also suffering from the bigint problem, so I think I'll leave this as-is.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit a51e361 into DefinitelyTyped:master Jul 25, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

I just published @types/underscore@1.10.14 to npm.

astorije pushed a commit to astorije/DefinitelyTyped that referenced this pull request Jul 30, 2020
…rray Tests - Max, Min, and Size by @reubenrybnik

* Updating type definitions for max, min, and size and adding tests.

* Allowing max and min iteratees to return any value instead of only numbers since several other types can be comparable in ways that work with these functions.
danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
…rray Tests - Max, Min, and Size by @reubenrybnik

* Updating type definitions for max, min, and size and adding tests.

* Allowing max and min iteratees to return any value instead of only numbers since several other types can be comparable in ways that work with these functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author is Owner The author of this PR is a listed owner of the package. Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Underscore collections functions should take objects

3 participants