-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[react]: Infer state type for useReducer #64412
Conversation
@mfp22 Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through. This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. InactiveThis PR has been inactive for 31 days — it is considered abandoned, and therefore closed! Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 64412,
"author": "mfp22",
"headCommitOid": "abf1a80ae12b0dba53c3216926288d673c685313",
"mergeBaseOid": "be21e88d0d7bd8d3714ae3af1baf9f9f925e456e",
"lastPushDate": "2023-04-23T03:09:48.000Z",
"lastActivityDate": "2023-04-23T03:47:18.000Z",
"hasMergeConflict": false,
"isFirstContribution": true,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "react",
"kind": "edit",
"files": [
{
"path": "types/react/index.d.ts",
"kind": "definition"
},
{
"path": "types/react/test/hooks.tsx",
"kind": "test"
}
],
"owners": [
"johnnyreilly",
"bbenezech",
"pzavolinsky",
"ericanderson",
"DovydasNavickas",
"theruther4d",
"guilhermehubner",
"ferdaber",
"jrakotoharisoa",
"pascaloliv",
"hotell",
"franklixuefei",
"Jessidhia",
"saranshkataria",
"lukyth",
"eps1lon",
"zieka",
"dancerphil",
"dimitropoulos",
"disjukr",
"vhfmag",
"hellatan",
"priyanshurav",
"Semigradsky"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "stale",
"reviewer": "eps1lon",
"date": "2023-02-22T21:23:18.000Z",
"abbrOid": "5eac079"
}
],
"mainBotCommentID": 1435649006,
"ciResult": "fail",
"ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/abf1a80ae12b0dba53c3216926288d673c685313/checks?check_suite_id=12418770497"
} |
🔔 @johnnyreilly @bbenezech @pzavolinsky @ericanderson @DovydasNavickas @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @eps1lon @zieka @dancerphil @dimitropoulos @disjukr @vhfmag @hellatan @priyanshurav @Semigradsky — please review this PR in the next few days. Be sure to explicitly select |
types/react/index.d.ts
Outdated
// NOTE 2: The past concern around autocompletion with the returned state object | ||
// seems to no longer be an issue. See https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/63607 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove NOTE and NOTE 2 now.
I can't even get autocomplete to work with the previous typings (down to TS 3.3): Playground with previous types
Proposed typings don't have autocomplete either: Playground with proposed types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange. It works in the StackBlitz I made. If you go to line 40 and erase the count
property and start typing again it autocompletes it. https://stackblitz.com/edit/react-ts-gy5gv6?file=App.tsx
Anyway, pipeline failed so I'm exploring that. And I'll erase those notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My overload is being used but the other specific overloads are causing my overload to not be able to infer the type. I will explore this more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eps1lon I came up with something that might work. 2 overloads instead of 6. I just updated this PR.
Tests pass locally except for the test I added in this PR. I don't know why, because in VSCode running 5.0.0-dev20221218 It's correctly inferring how I want so the test should pass, and in the TS environment like what you shared, it's inferring correctly with v4.9.5. If it's failing for me locally, I bet it will fail in the pipeline. If it does fail, should I just remove my added test? It will pass existing tests and apparently sometimes be better than what's there now.
In VSCode it's autocompleting, and I just confirmed it is in the TS environment too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less overloads is always a win. Especially if we can have 3 or less overloads since that has poor debuggability: microsoft/TypeScript#52745
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it failed in the pipeline for some reason. I'll try to figure it out a bit longer, but I could just remove my test and make this a "simplify useReducer overloads" PR (maybe it fixes autocomplete too) and in every environment except whatever this specific one is, it will infer the reducer state like I wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it passing everything locally! $ExpectType
is very picky and not helpful at telling you how you're using it wrong. But now I know.
@mfp22 The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
@mfp22 The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files. react (unpkg)was missing the following properties:
|
@eps1lon 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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super excited to see this land while also reducing the number of overloads.
I need to double check, but I think this might cause some breakages if people specify the type parameters since some signatures are now gone. But I have to double check. Want to test this on some larger repos anyway before landing.
Leaving the requested changes mostly, so this doesn't get merged before we do some integration testing.
@mfp22 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. Thank you! |
Draft should be good - that aughta remove it from the maintainer queue. |
@mfp22 Unfortunately, this pull request currently has a merge conflict 😥. Please update your PR branch to be up-to-date with respect to master. Have a nice day! |
@mfp22 I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Apr 26th (in a week) if the issues aren't addressed. |
@mfp22 The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
@mfp22 The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
@eps1lon I don't understand how this build could have failed with just the changes in this PR. It looks like it doesn't have anything to do with I also noticed a |
@mfp22 I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on May 23rd (in a week) if the issues aren't addressed. |
@mfp22 To keep things tidy, we have to close PRs that aren't mergeable and don't have activity in the last month. No worries, though — please open a new PR if you'd like to continue with this change. Thank you! |
@eps1lon Does this mean this PR can be resurrected soon? https://www.reddit.com/r/reactjs/comments/1ajur2f/is_there_any_news_on_react_19/ |
It will be part of the React 19 release. I already have a branch that includes the commits from this PR. |
npm test <package to test>
.Select one of these and delete the others:
If changing an existing definition: