Skip to content

[@types/underscore] Collection and Array Tests - Where, FindWhere, Shuffle, and Sample#46035

Merged
typescript-bot merged 11 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-where-findWhere-shuffle-sample
Jul 15, 2020
Merged

[@types/underscore] Collection and Array Tests - Where, FindWhere, Shuffle, and Sample#46035
typescript-bot merged 11 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-where-findWhere-shuffle-sample

Conversation

@reubenrybnik
Copy link
Copy Markdown
Contributor

@reubenrybnik reubenrybnik commented Jul 12, 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 where, findWhere, shuffle, and sample.
  • Updates where and findWhere to take a Partial<T> instead of an object to provide better autocomplete support where available and provide an error for inline object declarations with no matching properties.
  • Updates the overload of sample in which n is not provided to include undefined as a possible result (for the case where an empty collection is provided).
  • Updates the return type for _Chain.findWhere to include undefined.
  • Removes the redeclaration of the T generic in Underscore.sample and _Chain.sample which will fix Inaccurate typings for underscore's _.sample method #20440 for those functions.
  • Updates the return type of _Chain.where, _Chain.shuffle, and _Chain.sample to use the correct wrapped value type V to partially fix @types/underscore error TS2322 for _.chain after upgrade to v1.9 #36308.
  • Updates UnderscoreStatic.where and UnderscoreStatic.findWhere 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 12, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Jul 12, 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": 46035,
  "author": "reubenrybnik",
  "owners": [
    "borisyankov",
    "jbaldwin",
    "ccurrens",
    "confususs",
    "jgonggrijp",
    "ffflorian",
    "regevbr",
    "peterblazejewicz",
    "reubenrybnik"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "a702ec5",
  "headCommitOid": "a702ec534210c6c37684ed0923c519dc77e5926a",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastPushDate": "2020-07-14T06:37:48.000Z",
  "lastCommentDate": "2020-07-15T13:54:06.000Z",
  "maintainerBlessed": false,
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46035/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-14T11:45:41.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 12, 2020
@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 #46035 diff
Batch compilation
Memory usage (MiB) 55.6 58.7 +5.6%
Type count 9635 9702 +1%
Assignability cache size 1493 1519 +2%
Language service
Samples taken 4106 4326 +5%
Identifiers in tests 4106 4326 +5%
getCompletionsAtPosition
    Mean duration (ms) 177.9 179.8 +1.1%
    Mean CV 11.0% 10.6%
    Worst duration (ms) 349.5 341.1 -2.4%
    Worst identifier _ _
getQuickInfoAtPosition
    Mean duration (ms) 170.4 172.3 +1.2%
    Mean CV 11.0% 10.7% -2.7%
    Worst duration (ms) 331.5 336.9 +1.6%
    Worst identifier extractChainTypes reduce

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 12, 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.

I have some concerns about your tests, but I totally agree with your type declarations.

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jul 12, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed Revision needed This PR needs code changes before it can be merged. labels Jul 13, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@reubenrybnik The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Jul 13, 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'm happy with it as is, but if you decide to add a workaround for the Partial<any[]> problem, I'll happily press "approve" again.

@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 14, 2020
@reubenrybnik
Copy link
Copy Markdown
Contributor Author

There are two new errors in my company's solution with these changes. Both are caused by explicitly specified generics for findWhere being incorrect, which is an expected issue to have with these changes.

This set of functions aren't ones that we tend to use very often, so this admittedly isn't necessarily as useful a check this time around as it has been in previous PRs.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Oh yeah, and also this error which per the discussion seems like it's likely a good error to surface.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit 9c7a966 into DefinitelyTyped:master Jul 15, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
…rray Tests - Where, FindWhere, Shuffle, and Sample by @reubenrybnik

* Updating type definitions for where, findWhere, shuffle, and sample and adding tests.

* Fixing a test group comment in map that was missing its collection type differentiator.

* Adding "any" tests for where and findWhere.

* Fixing various issues.

* Adding a pair of tests to verify that Partial works well with a pair of type union cases.

* Updating chained-together tests for where, findWhere, shuffle, and sample to make more sense in the real world.

* Dropping the word "inline" from a comment.

* Adding a test that chains where up with previously updated functions.

* Adding sample into the mix and swapping out map for pluck.

* Fixing a CI failure.

* Using different parameter names for iteratees that interact with different types of collection items.
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

3 participants