Skip to content

Conversation

@eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Aug 2, 2024

This was implicitly enabled by TypeScript allowing any return type if the return type of an expected function is void. But this is not generally behavior we want in React so we should not relly on it.

It's also problematic since certain type-aware ESLint rules may issue violations since it looks like Form Actions can't be async.

We now explicitly codify support of async Form Actions. This also means return anything else will now issue type errors

Closes #64451 (comment)

This was implicitly enabled by TypeScript allowing any return type if the return type of an expected function is `void`.
But this is not generally behavior we want in React so we should not relly on it.

It's also problematic since certain type-aware ESLint rules may issue violations since it looks like Form Actions can't be async.

We now explicitly codify support of async Form Actions. This also means return anything else will now issue type errors
@typescript-bot
Copy link
Contributor

typescript-bot commented Aug 2, 2024

@eps1lon Thank you for submitting this PR!

This is a live comment that 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 passed
  • ✅ Most recent commit is approved by a DT maintainer

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": 70197,
  "author": "eps1lon",
  "headCommitOid": "415a5f0ab1791814ef5ca1c33e95ea7590a10396",
  "mergeBaseOid": "e433a575b5289eaf881b332f9cfaed17ac358226",
  "lastPushDate": "2024-08-02T13:45:57.000Z",
  "lastActivityDate": "2024-09-24T13:51:15.000Z",
  "mergeOfferDate": "2024-09-23T18:40:24.000Z",
  "mergeRequestDate": "2024-09-24T13:51:15.000Z",
  "mergeRequestUser": "eps1lon",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "react",
      "kind": "edit",
      "files": [
        {
          "path": "types/react/canary.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/test/canary.tsx",
          "kind": "test"
        },
        {
          "path": "types/react/ts5.0/canary.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/ts5.0/test/canary.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",
        "mattpocock"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-09-23T18:39:47.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 2265440407,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. labels Aug 2, 2024
@typescript-bot
Copy link
Contributor


interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_FORM_ACTIONS {
functions: (formData: FormData) => void;
functions: (formData: FormData) => void | Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you want this to be Promise | undefined instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think that?

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Aug 9, 2024
@typescript-bot
Copy link
Contributor

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

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

@eps1lon 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 Sep 11th (in a week) if the issues aren't addressed.

@typescript-bot
Copy link
Contributor

@eps1lon 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 eps1lon reopened this Sep 13, 2024
@typescript-bot typescript-bot added Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. and removed Revision needed This PR needs code changes before it can be merged. Abandoned This PR had no activity for a long time, and is considered abandoned labels Sep 13, 2024
@typescript-bot
Copy link
Contributor

It has been more than two weeks and this PR still has no reviews.

I'll bump it to the DT maintainer queue. Thank you for your patience, @eps1lon.

(Ping @johnnyreilly, @bbenezech, @pzavolinsky, @ericanderson, @DovydasNavickas, @theruther4d, @guilhermehubner, @ferdaber, @jrakotoharisoa, @pascaloliv, @Hotell, @franklixuefei, @Jessidhia, @saranshkataria, @lukyth, @zieka, @dancerphil, @dimitropoulos, @disjukr, @vhfmag, @hellatan, @priyanshurav, @Semigradsky, @mattpocock.)

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Sep 23, 2024
@eps1lon
Copy link
Collaborator Author

eps1lon commented Sep 24, 2024

Ready to merge

@typescript-bot typescript-bot merged commit 154a9c0 into DefinitelyTyped:master Sep 24, 2024
@eps1lon eps1lon deleted the react/async-form-actions branch September 24, 2024 13:52
@lionelrudaz
Copy link

Hey @eps1lon, thanks for the fix. I run into an issue and I believe this is related.

If the server action returns a value, for example to be used along with useActionState(), then there's a typescript error on the Form action attribute. As it expects a Promise response (most likely due to revalidatePath or redirect), there's an error if the action returns a value, like an error.

Any idea how we can fix that?

@eps1lon
Copy link
Collaborator Author

eps1lon commented Nov 20, 2024

void is to signal that the return type is ignored. If you're sure that you both want to return a value but ignore it in certain positions, you should ignore the error or use an intermediate function that voids the return.

alino20 pushed a commit to alino20/DefinitelyTyped that referenced this pull request Dec 31, 2024
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. Critical package Maintainer Approved 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.

5 participants