How to access types for action methods that return multiple types #12613
-
We have a v7 action method that looks something like this: export const action = async ({ request, params }: Route.ActionArgs) => {
if (someCondition) {
return { error: "some error" };
}
return redirect('/some-url');
} I want to use export default function MyComponent({ actionData }: Route.ComponentProps) {
// Do something with `actionData`
} But the type of I couldn't find anything in the docs about how to support this - what is best practice here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Don't return the |
Beta Was this translation helpful? Give feedback.
Don't return the
redirect
, throw it instead, so it won't appear in the return type. If you still need to return objects with different structures depending on what happened in the action, use a tagged union.