Skip to main content




Type of options when creating a new safe action client.

export type SafeClientOpts<Context, MiddlewareData> = {
handleServerErrorLog?: (e: Error) => MaybePromise<void>;
handleReturnedServerError?: (e: Error) => MaybePromise<string>;
middleware?: (parsedInput: any, data?: MiddlewareData) => MaybePromise<Context>;


Type of the function called from Client Components with typesafe input data.

type SafeAction<S extends Schema, Data> = (input: InferIn<S>) => Promise<{
data?: Data;
serverError?: string;
validationErrors?: Partial<Record<keyof Infer<S> | "_root", string[]>>;


Type of the function that executes server code when defining a new safe action.

type ServerCodeFn<S extends Schema, Data, Context> = (
parsedInput: Infer<S>,
ctx: Context
) => Promise<Data>;



Type of result object returned by useAction and useOptimisticAction hooks.

If a server-client communication error occurs, fetchError will be set to the error message.

type HookResult<S extends Schema, Data> = Awaited<ReturnType<SafeAction<S, Data>>> & {
fetchError?: string;


Type of hooks callbacks. These are executed when action is in a specific state.

type HookCallbacks<S extends Schema, Data> = {
onExecute?: (input: InferIn<S>) => MaybePromise<void>;
onSuccess?: (data: Data, input: InferIn<S>, reset: () => void) => MaybePromise<void>;
onError?: (
error: Omit<HookResult<S, Data>, "data">,
input: InferIn<S>,
reset: () => void
) => MaybePromise<void>;
onSettled?: (
result: HookResult<S, Data>,
input: InferIn<S>,
reset: () => void
) => MaybePromise<void>;


Type of the action status returned by useAction and useOptimisticAction hooks.

type HookActionStatus = "idle" | "executing" | "hasSucceeded" | "hasErrored";

TypeSchema library

Infer, InferIn, Schema types come from TypeSchema library.