Skip to content

[@types/underscore] Object Tests - MapObject, Pairs, and FindKey#46422

Merged
typescript-bot merged 14 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-mapObject-paris-findKey
Jul 31, 2020
Merged

[@types/underscore] Object Tests - MapObject, Pairs, and FindKey#46422
typescript-bot merged 14 commits intoDefinitelyTyped:masterfrom
reubenrybnik:underscore-tests-mapObject-paris-findKey

Conversation

@reubenrybnik
Copy link
Copy Markdown
Contributor

  • 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 is an addendum to the original the planned set for #45201 and includes the following changes:

  • Adds tests for mapObject, pairs, and findKey.
  • Updates collection and dictionary types and iterators to allow a fallback item type to be specified rather than always falling back to never.
  • Adds an ObjectIteratee and ObjectIterateeResult type.
  • Updates mapObject to use ObjectIteratee and ObjectIterateeResult.
  • Updates pairs to try to figure out what its value element is if it can.
  • Updates findKey to use ObjectIteratee.
  • Updates mapObject and findKey in Underscore and _Chain to be more in sync with UnderscoreStatic.

@typescript-bot typescript-bot added 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 29, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Jul 29, 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": 46422,
  "author": "reubenrybnik",
  "owners": [
    "borisyankov",
    "jbaldwin",
    "ccurrens",
    "confususs",
    "jgonggrijp",
    "ffflorian",
    "regevbr",
    "peterblazejewicz",
    "reubenrybnik"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "1b03f4d",
  "headCommitOid": "1b03f4d13078717e6c797e315c34517ad13d86e7",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastPushDate": "2020-07-31T17:29:27.000Z",
  "lastCommentDate": "2020-07-31T23:44:51.000Z",
  "maintainerBlessed": false,
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46422/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-31T22:53:23.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.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

As a quick disclaimer here, my company's solution does not use mapObject or pairs at all in TS code and only uses findKey once, so testing the change in my own code doesn't do much in this case.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Well, I can still take the test code and verify that it does the things I expect in JS at least.

@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 #46422 diff
Batch compilation
Memory usage (MiB) 66.4 60.1 -9.5%
Type count 12952 13446 +4%
Assignability cache size 1521 1632 +7%
Language service
Samples taken 7436 7766 +4%
Identifiers in tests 7436 7766 +4%
getCompletionsAtPosition
    Mean duration (ms) 176.6 177.5 +0.5%
    Mean CV 9.2% 9.4%
    Worst duration (ms) 335.8 377.1 +12.3%
    Worst identifier _ resultUnionPartialMemoIterator
getQuickInfoAtPosition
    Mean duration (ms) 173.0 173.9 +0.5%
    Mean CV 9.4% 9.6% +2.7%
    Worst duration (ms) 337.7 359.4 +6.4%
    Worst identifier reduce extractUnderscoreTypes

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

This review seems familiar, somehow...

As always, I should acknowledge that your changes are already an improvement over the old situation!

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jul 30, 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 removed the Revision needed This PR needs code changes before it can be merged. label Jul 30, 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?

…t that resolved to Partial<any> in the non-collection case now, which is probably more or less object (though it might be worth converting that to object if that's not the case).
@reubenrybnik
Copy link
Copy Markdown
Contributor Author

As a quick point of interest, I've found that Partial<any> only allows objects to be assigned to it, so it is an acceptable type to end up with if necessary when one wants to make sure that a provided value is an object.

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Thanks @jgonggrijp, it's much nicer to have the iteratee types consolidated and to be providing more specific results for findKey. I think this is ready for another look whenever you have a moment.

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.

This is good stuff!

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.

Excellent.

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

Awesome @jgonggrijp, hope you're having a great time! Let me know if you'd like me to hold off on further PRs for a bit 😄

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

reubenrybnik commented Jul 31, 2020

Also thanks for the extra-excellent review on this one!

@reubenrybnik
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit 7032a7e into DefinitelyTyped:master Jul 31, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

@jgonggrijp
Copy link
Copy Markdown
Contributor

My pleasure, @reubenrybnik! You don't need to hold off for me, but feel free to do it anyway, of course.

Since this appears to be a natural moment for a break in your series, I'd like to briefly mention my Patreon page. I believe that improving what is already there, rather than creating something new from scratch, is the best way to move forward as a planet. This is why I contribute to open source software, including reviews like these. While I will never stop contributing, receiving more donations would help me dedicate more time to the common good. If you, your company, or anyone else reading this would be willing to make a pledge, that would be great.

https://www.patreon.com/juliangonggrijp

danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
…apObject, Pairs, and FindKey by @reubenrybnik

* Updating type definitions for mapObject, pairs, and findKey and adding tests.

* Also updating Underscore.property to match the update to UnderscoreStatic.property.

* Adding a few more tests.

* Combining Iteratee with ObjectIteratee and IterateeResult with ObjectIterateeResult.

* Improving the condition for choosing between Partial<T> and object.

* Fixing a test that breaks slightly with iteratee changes.

* Updating findKey to result in keyof V rather than just string.

* Updating the documentation of pairs to refer to a specific signature of _.object (and to refer to _.object at all in the case of Underscore and _Chain).

* Dropping object and just going with Partial<T> because I realized that that resolved to Partial<any> in the non-collection case now, which is probably more or less object (though it might be worth converting that to object if that's not the case).

* Handling the possibility of a property that is a type union as well as I can.

* Switching constraints from dictionaries to collections since arrays are objects and technically work.

* Adding a comment above the assignability test.

* Defaulting to a collection type of any for non-collections when evaluating iteratee results.

* Using Extract instead of making up a new type and also using keyof V in paris as recommended by @jgonggrijp.
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.

3 participants