mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
ea4bc04e94
* feat: ActionReturnType util * feat(test): ActionReturnType * chore: changeset
705 B
705 B
astro |
---|
patch |
Expose new ActionReturnType
utility from astro:actions
. This infers the return type of an action by passing typeof actions.name
as a type argument. This example defines a like
action that returns likes
as an object:
// actions/index.ts
import { defineAction } from 'astro:actions';
export const server = {
like: defineAction({
handler: () => {
/* ... */
return { likes: 42 }
}
})
}
In your client code, you can infer this handler return value with ActionReturnType
:
// client.ts
import { actions, ActionReturnType } from 'astro:actions';
type LikesResult = ActionReturnType<typeof actions.like>;
// -> { likes: number }