Replies: 1 comment
-
So far I ended up with this: import { data } from "react-router";
export function createServerAction<
ActionFunc extends (...args: any[]) => Promise<any>,
>(actionFunc: ActionFunc) {
async function serverAction(
...args: Parameters<typeof actionFunc>
): Promise<Awaited<ReturnType<typeof actionFunc> | ReturnType<typeof data>>> {
try {
const data = await actionFunc(...args);
return data;
} catch (error) {
return data(error, {
headers: new Headers([["Content-Type", "application/json"]]),
status: 500,
});
}
}
return serverAction;
} However another issue is I need to apply some transformation to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a factory like this:
But obviously the page doesn't like its signature when used like this:
But it's not obvious how is
Route.ActionArgs
constructing itself.Looking at generated types it uses
CreateServerActionArgs<Info>
from"react-router/route-module"
, but theInfo
is a bare type not extending a specific interface, so do I have to pass it as a generic parameter?Beta Was this translation helpful? Give feedback.
All reactions