[@types/underscore] Collection and Array Tests - OOP, Chain, and Chunk#45304
Conversation
…lists, one for dictionaries, and one for other values - that preserve the correct wrapped value types.
… using a disguised type assertion.
…ince several Underscore functions apply to single values (e.g. bind, partial, is*, and range).
… instead of any since that's very close to being the minimum supported version at this time.
|
@reubenrybnik Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 - keep an eye on this comment as I'll be updating it with information as things progress. 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": 45304,
"author": "reubenrybnik",
"owners": [
"borisyankov",
"jbaldwin",
"ccurrens",
"confususs",
"jgonggrijp",
"ffflorian",
"regevbr",
"peterblazejewicz"
],
"dangerLevel": "ScopedAndTested",
"headCommitAbbrOid": "3835c33",
"headCommitOid": "3835c33848aed8f30912d06e75e9074c51cf5d6d",
"mergeIsRequested": true,
"stalenessInDays": 0,
"lastCommitDate": "2020-06-18T04:46:45.000Z",
"lastCommentDate": "2020-06-18T21:08:31.000Z",
"reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45304/files",
"hasMergeConflict": false,
"authorIsOwner": false,
"isFirstContribution": true,
"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-06-18T17:54:01.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?
Looks like there were a couple significant differences—take a look at worst-case duration for getting completions at a position and worst-case duration for getting quick info at a position to make sure everything looks ok. |
|
Oh yeah, this should fix #7931 (added a mention of that to the description). |
jgonggrijp
left a comment
There was a problem hiding this comment.
I have some comments I'd like to see addressed, though not necessarily by code changes.
I definitely think that you fixed some problems with chunk and I'm happy for _ChainSingle to go.
|
@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! |
…ed any features from higher TS versions in this set of revisions since any is perferable to unknown.
|
...I'm very confused now about what precisely the benchmark check is measuring...but I'll take the Perf: Same label 😄 |
|
I'm starting to like this more and more, @reubenrybnik. Please let me know when you want to try again whether I'll hit "approve". |
|
@jgonggrijp sorry to have left this sitting for a bit, I think I have this in a reasonable state for a merge at this point if you don't mind merging a few tests that may get replaced later. I'll work on putting together either a direct switch or transition plan to a different testing strategy for chain as you had requested before putting up more PRs, but I can also put this in a draft state for a bit to get it off the board while I try to work that out if you prefer. |
|
@reubenrybnik As far as you're concerned, is the current state of the current PR an improvement over the master branch (even though transitional)? |
|
@jgonggrijp I believe it is, yes, though it's only the first part of what I'd like to achieve 😄
|
|
Wait, but I can make it slightly better! I can add the previously-failing example for #7931 as a test actually, which will be nice too because it's the kind of chain test you were hoping for @jgonggrijp 😄 |
… it works when switching from _ChainSingle to _Chain.
…_Chain since several Underscore functions apply to single values (e.g. bind, partial, is*, and range)." This reverts commit 5daf47b.
…m types when given values that are not collection types.
|
I did one more sanity check of building my company's repository with the updates I made in my most recent set of changes, and the result was one new legitimate build error where we're passing an object to |
|
Thanks a lot @jgonggrijp for all of your feedback and help in this PR! Your input definitely resulted in valuable improvements to the overall result and a good amount of food for thought for me, and I look forward to looking into tests for |
|
Ready to merge |
|
My pleasure! |
…rray Tests - OOP, Chain, and Chunk by @reubenrybnik * Updating both underscore and chain to have three overloads - one for lists, one for dictionaries, and one for other values - that preserve the correct wrapped value types. * Updating Underscore.value to return the wrapped value type instead of using a disguised type assertion. * Updating _Chain.chain to continue chaining the wrapped value type. * Removing the _ChainSingle interface in favor of always using _Chain since several Underscore functions apply to single values (e.g. bind, partial, is*, and range). * Adding tests for OOP Style and Chaining. * Adding myself to the set of Underscore type definition authors. * Adding a newline back to the end of the tests file. * Moving the minimum supported TS version to 3.0 so unknown can be used instead of any since that's very close to being the minimum supported version at this time. * Making some updates to summary comments. * Removing extra lines in tests. * Updating chunk. * Adding tests for chunk. * Changing the minimum TS version back to 2.8 since I probably won't need any features from higher TS versions in this set of revisions since any is perferable to unknown. * Reordering tests so new ones are appended to the file rather than prepended. * Adding a newline to the end of underscore-tests.ts. * Removing tests that explicitly specify generics and moving $ExpectType assertions to the ends of the lines that they're testing. * Adding tests for more specific list and dictionary types, switching to only using $ExpectType for result type testing, and getting rid of some extra scoping braces now that they're not needed. * Fixing incorrect JSDoc terminators for chunk functions. * Adding the example from DefinitelyTyped#7931 as a test to verify that it works when switching from _ChainSingle to _Chain. * Revert "Removing the _ChainSingle interface in favor of always using _Chain since several Underscore functions apply to single values (e.g. bind, partial, is*, and range)." This reverts commit 5daf47b. * Updating the Collection type to be more accurate and useful. * Updating _ChainSingle to be an alias to _Chain<TypeOfCollection<V>, V>. * Also updating the Underscore and chain functions to use never for item types when given values that are not collection types. * Adding a few more tests around ChainSingle results. Co-authored-by: Mike Ness <mness@clearcompany.com>
…rray Tests - OOP, Chain, and Chunk by @reubenrybnik * Updating both underscore and chain to have three overloads - one for lists, one for dictionaries, and one for other values - that preserve the correct wrapped value types. * Updating Underscore.value to return the wrapped value type instead of using a disguised type assertion. * Updating _Chain.chain to continue chaining the wrapped value type. * Removing the _ChainSingle interface in favor of always using _Chain since several Underscore functions apply to single values (e.g. bind, partial, is*, and range). * Adding tests for OOP Style and Chaining. * Adding myself to the set of Underscore type definition authors. * Adding a newline back to the end of the tests file. * Moving the minimum supported TS version to 3.0 so unknown can be used instead of any since that's very close to being the minimum supported version at this time. * Making some updates to summary comments. * Removing extra lines in tests. * Updating chunk. * Adding tests for chunk. * Changing the minimum TS version back to 2.8 since I probably won't need any features from higher TS versions in this set of revisions since any is perferable to unknown. * Reordering tests so new ones are appended to the file rather than prepended. * Adding a newline to the end of underscore-tests.ts. * Removing tests that explicitly specify generics and moving $ExpectType assertions to the ends of the lines that they're testing. * Adding tests for more specific list and dictionary types, switching to only using $ExpectType for result type testing, and getting rid of some extra scoping braces now that they're not needed. * Fixing incorrect JSDoc terminators for chunk functions. * Adding the example from DefinitelyTyped#7931 as a test to verify that it works when switching from _ChainSingle to _Chain. * Revert "Removing the _ChainSingle interface in favor of always using _Chain since several Underscore functions apply to single values (e.g. bind, partial, is*, and range)." This reverts commit 5daf47b. * Updating the Collection type to be more accurate and useful. * Updating _ChainSingle to be an alias to _Chain<TypeOfCollection<V>, V>. * Also updating the Underscore and chain functions to use never for item types when given values that are not collection types. * Adding a few more tests around ChainSingle results. Co-authored-by: Mike Ness <mness@clearcompany.com>
npm test.)npm run lint package-name(ortscif notslint.jsonis present).This PR is the first in a planned set that will add a standardized set of happy path tests for all Underscore Collection and Array functions (as well as OOP and Chain) and update the type definitions to pass those tests. Chunk is included in this PR because the return type for that function references Collection and it's important for that to not be the case sooner rather than later. The other changes are pretty straightforward for the most part, but I did remove _ChainSingle in favor of just using _Chain because Underscore provides several functions that it could be useful to call on a wrapped single value as part of a chain (bind/partial on functions, is* on anything, range on numbers, values on an object, etc.) to fix #7931. Because
_Chainis defined as_Chain<T, V = T>and itsvaluefunction is defined asvalue(): V;, replacing references to_ChainSingle<T>with_Chain<T>will provide an exact equivalent to_ChainSingle<T>'svalue(): T;function.An unpolished version of the full set of changes that I intend to make can be found in #45201, and the full set of PRs that I expect to create to accomplish this are below. I've prepared two additional branches for future PRs at this time (diff links are included below) but don't want to go further until I've had a chance to get feedback on these initial changes and the format of the tests in general.
Round 1 (a few base changes)
Round 2 (new types that will be repeatedly referenced in other PRs)
Round 3 (the remaining Collection functions)
Round 4 (the remaining Array functions)
Update: After revisions, this ended up updating
UnderscoreStatic.samplein a way that fixes #20440 (on that interface at least) because it redefinedCollection<T>to not be an empty interface soTcould be inferred from the provided collection.