chungweileong94 / server-act

A simple React server action builder
MIT License
20 stars 1 forks source link

Improve action optional param type #18

Closed chungweileong94 closed 5 months ago

chungweileong94 commented 5 months ago

Why?

Currently, if you try to pass an action without input into <form> action prop, it will throw type error below

image

After the fix

Empty input

const action = serverAct.action(async () => Promise.resolve('bar'));
//     ^?  () => Promise<string>

Non-optional input

const action = serverAct.input(z.string()).action(async () => Promise.resolve('bar'));
//     ^?  (input: string) => Promise<string>

Optional input

const action = serverAct.input(z.string().optional()).action(async () => Promise.resolve('bar'));
//     ^?  (input?: string | undefined) => Promise<string>
stackblitz[bot] commented 5 months ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

changeset-bot[bot] commented 5 months ago

🦋 Changeset detected

Latest commit: b1cbc4a3ba62d3613d8ada41794c900676e9636b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------- | ----- | | server-act | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR