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
29 lines
705 B
Markdown
29 lines
705 B
Markdown
---
|
|
'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:
|
|
|
|
```ts
|
|
// 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`:
|
|
|
|
```ts
|
|
// client.ts
|
|
import { actions, ActionReturnType } from 'astro:actions';
|
|
|
|
type LikesResult = ActionReturnType<typeof actions.like>;
|
|
// -> { likes: number }
|
|
```
|