Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

mfp22
Copy link

@mfp22 mfp22 commented Feb 18, 2023

Select one of these and delete the others:

If changing an existing definition:

  • [ x] Provide a URL to documentation or source code which provides context for the suggested changes: <>

@typescript-bot
Copy link
Contributor

typescript-bot commented Feb 18, 2023

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

Code Reviews

Because 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

  • ✅ No merge conflicts
  • ❌ Continuous integration tests have failed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This 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"
}

@typescript-bot
Copy link
Contributor

Comment on lines 988 to 989
// 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
Copy link
Collaborator

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

Copy link
Author

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

Copy link
Author

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.

Copy link
Author

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.

Copy link
Collaborator

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

Copy link
Author

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.
image

Copy link
Author

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.

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Feb 18, 2023
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Feb 18, 2023
@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Feb 18, 2023
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Feb 18, 2023
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Feb 18, 2023
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Feb 18, 2023
@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Feb 18, 2023
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Feb 18, 2023
@DangerBotOSS
Copy link

DangerBotOSS commented Feb 18, 2023

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

react (unpkg)

was missing the following properties:

  1. unstable_act

Generated by 🚫 dangerJS against cebd684

@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Feb 18, 2023
Copy link
Collaborator

@eps1lon eps1lon left a 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.

types/react/index.d.ts Show resolved Hide resolved
@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Feb 18, 2023
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Needs Author Action in New Pull Request Status Board Feb 18, 2023
@typescript-bot
Copy link
Contributor

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

@weswigham
Copy link
Contributor

Draft should be good - that aughta remove it from the maintainer queue.

@typescript-bot typescript-bot added Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Mar 29, 2023
@typescript-bot typescript-bot moved this from Needs Maintainer Action to Needs Author Action in New Pull Request Status Board Mar 29, 2023
@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Apr 21, 2023
@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot removed Has Merge Conflict This PR can't be merged because it has a merge conflict. The author needs to update it. Abandoned This PR had no activity for a long time, and is considered abandoned labels Apr 23, 2023
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Apr 23, 2023
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Apr 23, 2023
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Apr 23, 2023
@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Apr 23, 2023
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Apr 23, 2023
@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Apr 23, 2023
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Apr 23, 2023
@typescript-bot
Copy link
Contributor

@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
Copy link
Author

mfp22 commented Apr 23, 2023

@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 useReducer. https://github.com/DefinitelyTyped/DefinitelyTyped/actions/runs/4776139211/jobs/8490968425?pr=64412

I also noticed a ts5 folder. Should I add my changes to that folder too?

@typescript-bot
Copy link
Contributor

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

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label May 16, 2023
@typescript-bot typescript-bot removed this from Needs Author Action in New Pull Request Status Board May 24, 2023
@typescript-bot
Copy link
Contributor

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

@mfp22
Copy link
Author

mfp22 commented Feb 11, 2024

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

@eps1lon
Copy link
Collaborator

eps1lon commented Feb 12, 2024

It will be part of the React 19 release. I already have a branch that includes the commits from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abandoned This PR had no activity for a long time, and is considered abandoned Critical package The CI failed When GH Actions fails
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants