You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I verified that the issue exists in the latest next-safe-action release
Is there an existing issue for this?
I have searched the existing issues and found nothing that matches
Describe the bug
When using next-safe-action with zod-safe-action schema, the useAction(...).input type is not inferred correctly.
In the action body the input type is ok:
constschema=zfd.formData({bar: zfd.text(z.string().min(3).max(10)),});exportconstdoSomethingWithZodFormData=actionClient.schema(schema).action(async({parsedInput: { bar }})=>{// Here the `bar` input is a `string` as expectedconstbaz: string=bar;return{/* ... */};});
The issue is only with the hook:
constdoSomethingWithZodFormActionAction=useAction(doSomethingWithZodFormData)// With a schema made with zod-safe-action, the input type is not ok: `FormData | FormDataLikeInput`constbar=doSomethingWithZodFormActionAction.input?.bar
The issue also present with the useAction(...).execute function.
Everything works correctly when using a zod schema.
Reproduction steps
In the linked reproduction sandbox, if you open the app/page.tsx file you will see two useAction usage: one with a zod schema, the other with a zod-safe-action schema. The second case trigger a TS error.
Expected behavior
As the input type is well inferred in the action, I'm expecting it to the be inferred when using the useAction hook.
I was once supporting this in my server action library chungweileong94/server-act#35, but I found myself fighting against the types for this specific use-case (zod-form-data), so I ended up ditching it when I adopted standard schema chungweileong94/server-act#37.
Are you using the latest version of this library?
Is there an existing issue for this?
Describe the bug
When using
next-safe-action
withzod-safe-action
schema, theuseAction(...).input
type is not inferred correctly.In the action body the input type is ok:
The issue is only with the hook:
The issue also present with the
useAction(...).execute
function.Everything works correctly when using a zod schema.
Reproduction steps
In the linked reproduction sandbox, if you open the
app/page.tsx
file you will see twouseAction
usage: one with azod
schema, the other with azod-safe-action
schema. The second case trigger a TS error.Expected behavior
As the input type is well inferred in the action, I'm expecting it to the be inferred when using the
useAction
hook.Link to a minimal reproduction of the issue
https://codesandbox.io/p/devbox/epic-torvalds-vt88n4
Library version
7.10.3
Next.js version
15.1.7
Node.js version
20.9.0
Additional context
No response
The text was updated successfully, but these errors were encountered: