The return type of a SafeFn is a ResultAsync<Value, Error> when using .run() or the useServerAction() hook, or an ActionResult<Value,Error> when calling the function returned by .createAction() directly.
ActionResult is a simple Result type that is used as a NeverThrow Result can
not be serialized and sent over the network. The useServerAction() hook
transforms this ActionResult back into a ResultAsync for you.
type E = { code: "INPUT_PARSING"; cause: { formattedError: z.ZodFormattedError<T>; flattenedError: z.typeToFlattenedError<T, string>; };};
With T as the input of your input schema (this differs from output when using things like .transform()). Only applicable if an input schema is defined.
If you defined a parent, its input type will be merged to create one single input error type.
type E = { code: "OUTPUT_PARSING"; cause: { formattedError: z.ZodFormattedError<T>; flattenedError: z.typeToFlattenedError<T, string>; };};
With T as the input of your output schema (this differs from output when using things like .transform()). Only applicable if an output schema is defined. If you defined a parent, its output type will be merged to create one single output error type.
The return type of child.run() or calling child.createAction() through the useServerAction() hook will be:
type Res = ResultAsync< { childOut: string; }, // Merged error from parent and child | { code: "INPUT_PARSING"; cause: { formattedError: z.ZodFormattedError<{ parentIn: string; childIn: string; }>; flattenedError: z.typeToFlattenedError< { parentIn: string; childIn: string; }, string >; }; } // Yielded error in parent | { code: "TOO_LOW!"; } // Parent did not specify a catch handler, so default is used | { code: "UNCAUGHT_ERROR"; cause: "An uncaught error occurred. You can implement a custom error handler by using `catch()`"; } // Specified in child catch handler | { code: "Woops!"; } // Output parsing error | { code: "OUTPUT_PARSING"; cause: { formattedError: z.ZodFormattedError<{ parentOut: string; childOut: string; }>; flattenedError: z.typeToFlattenedError< { parentOut: string; childOut: string; }, string >; }; }>;
when calling the returned function from .createAction() directly, the Value and Error types will be identical to the ones above, only wrapped in an ActionResult