-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[react-dom][useFormState] Allow sync actions #67266
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-dom][useFormState] Allow sync actions #67266
Conversation
Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files. react-dom (unpkg)was missing the following properties:
FormattingThe following files are not formatted:
Consider running |
@eps1lon Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it. 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. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 67266,
"author": "eps1lon",
"headCommitOid": "d823c700844a1303aca97d10207b7c6f0af1bf74",
"mergeBaseOid": "705e209914666815cdbf379eb6ee486cc603bf9f",
"lastPushDate": "2023-11-01T16:03:02.000Z",
"lastActivityDate": "2023-11-06T20:34:09.000Z",
"maintainerBlessed": "Waiting for Code Reviews",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "react-dom",
"kind": "edit",
"files": [
{
"path": "types/react-dom/canary.d.ts",
"kind": "definition"
},
{
"path": "types/react-dom/test/canary-tests.tsx",
"kind": "test"
}
],
"owners": [
"MartynasZilinskas",
"theruther4d",
"Jessidhia",
"eps1lon"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "unstubbable",
"date": "2023-11-06T20:34:09.000Z",
"isMaintainer": false
}
],
"mainBotCommentID": 1789259088,
"ciResult": "pass"
} |
🔔 @MartynasZilinskas @theruther4d @Jessidhia — please review this PR in the next few days. Be sure to explicitly select |
useFormState( | ||
action, | ||
// @ts-expect-error | ||
Promise.resolve(1), |
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.
Omitting the Awaited
from the initial state does not give me the expected error in this playground? What's the difference to the changes proposed in this PR? Are the tests running with different compiler settings? Or am I overlooking something?
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.
Yours is also missing the overload. I don't think tests here run with different options. But the diff is too big between my version and yours to say for sure what's happening.
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've found the difference in this playground. It does not yield the expected error when using a closure where the action state param type is inferred, instead of explicitly being annotated (as in your action
function):
useFormState(async (prevState) => prevState + 1, Promise.resolve(0));
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.
This is now handled since we also wanted to reduce useFormState<Promise<T>>
to State
being T
at every position.
@eps1lon 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 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 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. |
Fixes ``` Error: /home/runner/work/DefinitelyTyped/DefinitelyTyped/types/react-dom/test/canary-tests.tsx:158:9 ERROR: 158:9 expect [email protected] expected type to be: number got: 0 ERROR: 158:22 expect Compile error in [email protected] but not in [email protected]. Fix by adding '"minimumTypeScriptVersion": "5.0"' to package.json. No overload matches this call. Overload 1 of 2, '(action: (state: number) => number | Promise<number>, initialState: number, permalink?: string | undefined): [state: number, dispatch: () => void]', gave the following error. Argument of type '(prevState: 0) => Promise<number>' is not assignable to parameter of type '(state: number) => number | Promise<number>'. Types of parameters 'prevState' and 'state' are incompatible. Type 'number' is not assignable to type '0'. Overload 2 of 2, '(action: (state: number, payload: unknown) => number | Promise<number>, initialState: number, permalink?: string | undefined): [state: number, dispatch: (payload: unknown) => void]', gave the following error. Argument of type '(prevState: 0) => Promise<number>' is not assignable to parameter of type '(state: number, payload: unknown) => number | Promise<number>'. Types of parameters 'prevState' and 'state' are incompatible. Type 'number' is not assignable to type '0'. at testTypesVersion (/home/runner/work/DefinitelyTyped/DefinitelyTyped/node_modules/.pnpm/@DefinitelyTyped[email protected][email protected]/node_modules/@definitelytyped/dtslint/src/index.ts:202:11) at runTests (/home/runner/work/DefinitelyTyped/DefinitelyTyped/node_modules/.pnpm/@DefinitelyTyped[email protected][email protected]/node_modules/@definitelytyped/dtslint/src/index.ts:170:7) ELIFECYCLE Command failed with exit code 1. ```
8f37f63
to
d823c70
Compare
@unstubbable 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? |
Types for facebook/react#27571