Next.js Discord

Discord Forum

useActionState return type

Answered
Polar bear posted this in #help-forum
Open in Discord
Avatar
Polar bearOP
Is there a way to define a global type for the server action return type so all server actions can adhere to?
Answered by B33fb0n3
yes, you can set the return type of your server action directly to the function. Of course you can reuse the same type everywhere on all server actions: (see attached)
Image
Image
View full answer

5 Replies

Avatar
@Polar bear Is there a way to define a global type for the server action return type so all server actions can adhere to?
Avatar
yes, you can set the return type of your server action directly to the function. Of course you can reuse the same type everywhere on all server actions: (see attached)
Image
Image
Answer
Avatar
Polar bearOP
is there a way to set it globally like in a .d.ts file?
Avatar
@Polar bear is there a way to set it globally like in a `.d.ts` file?
Avatar
I don't think so, as every function is unique and will only be transformed into a server action at runtime. But typescript is not there during runtime
Avatar
sure thing