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

Server action causes TypeError when returning a value #70613

Open
grzegorzpokorski opened this issue Sep 30, 2024 · 0 comments
Open

Server action causes TypeError when returning a value #70613

grzegorzpokorski opened this issue Sep 30, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.

Comments

@grzegorzpokorski
Copy link

Link to the code that reproduces this issue

https://github.com/grzegorzpokorski/next-server-action-return-type

To Reproduce

  1. Clone reproduction repo: https://github.com/grzegorzpokorski/next-server-action-return-type
  2. Download deps and build project (pnpm i && pnpm build).
  3. During build you should recieve folowing type error:
./app/page.tsx:17:16
Type error: Type '(formData: FormData) => Promise<{ data: string; }>' is not assignable to type 'string | ((formData: FormData) => void | Promise<void>)'.
  Type '(formData: FormData) => Promise<{ data: string; }>' is not assignable to type '(formData: FormData) => void | Promise<void>'.
    Type 'Promise<{ data: string; }>' is not assignable to type 'void | Promise<void>'.
      Type 'Promise<{ data: string; }>' is not assignable to type 'Promise<void>'.
        Type '{ data: string; }' is not assignable to type 'void'.

  15 |   }
  16 |  
> 17 |   return <form action={createInvoice}>...</form>
     |                ^
  18 | }
   Linting and checking validity of types  ... ELIFECYCLE  Command failed with exit code 1.

Current vs. Expected behavior

Allow data to be returned from server action.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
  Available memory (MB): 7843
  Available CPU cores: 8
Binaries:
  Node: 20.16.0
  npm: 10.8.1
  Yarn: 1.22.22
  pnpm: 9.11.0
Relevant Packages:
  next: 15.0.0-canary.173 // Latest available version is detected (15.0.0-canary.173).
  eslint-config-next: N/A
  react: 19.0.0-rc-3edc000d-20240926
  react-dom: 19.0.0-rc-3edc000d-20240926
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

TypeScript

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

The mentioned type error occurs after upgrading @types/react to version 18.3.9 and later.
Example server action comes from documentation: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#forms

@grzegorzpokorski grzegorzpokorski added the bug Issue was opened via the bug report template. label Sep 30, 2024
@github-actions github-actions bot added the TypeScript Related to types with Next.js. label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant