Allow async event handler in <Form onSubmit> - #70086
Conversation
|
@ProchaLu 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 that 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 7 days. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 70086,
"author": "ProchaLu",
"headCommitOid": "07880a74014228262d42f97346fbdb05a055f608",
"mergeBaseOid": "66fe40c5267f780ad9718e534e478e2badadd9f7",
"lastPushDate": "2024-07-18T08:10:09.000Z",
"lastActivityDate": "2024-08-14T18:19:44.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"
}
],
"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": [],
"mainBotCommentID": 2235895040,
"ciResult": "fail",
"ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/07880a74014228262d42f97346fbdb05a055f608/checks?check_suite_id=26144406227"
} |
|
🔔 @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 — please review this PR in the next few days. Be sure to explicitly select |
|
@ProchaLu 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 that are failing do not end up on the list of PRs for the DT maintainers to review. |
|
Looks like we'd have to write a codemod now to ensure all event handlers are void: -<button onClick={() => returnSomethingOtherThanVoid()} />
+<button onClick={() => {returnSomethingOtherThanVoid()}} />That's the same we did for |
Oh, wouldn't this have already been a problem before with the Or does changing the event handler return type from |
Yes. TypeScript does not care if you pass |
|
Wow TIL about TypeScript, super interesting! function acceptEventHandler(eventHandler: () => void) {}
acceptEventHandler(() => 1)
function acceptEventHandlerWithAsyncFunction(eventHandler: () => void | Promise<void>) {}
acceptEventHandlerWithAsyncFunction(() => 1) // Type 'number' is not assignable to type 'void | Promise<void>'.(2322) |
|
@ProchaLu 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 Aug 21st (in a week) if the issues aren't addressed. |
|
@eps1lon @rickhanlonii, I wanted to follow up on this PR which adds support for @eps1lon mentioned that the team was discussing the potential pitfalls, like the issues with |
|
Part of the team was out so we didn't have time to discuss it yet. |
|
Closed React decided not to allow async functions at the type level in event handlers like |

Discussion #66505 (reply in thread)
This PR allows passing in async event handler for
onSubmit.cc @eps1lon
Please fill in this template.
pnpm test <package to test>.Select one of these and delete the others:
If adding a new definition:
.d.tsfiles generated via--declarationdts-gen --dt, not by basing it on an existing project.tsconfig.jsonshould havenoImplicitAny,noImplicitThis,strictNullChecks, andstrictFunctionTypesset totrue.If changing an existing definition:
Playground