diff --git a/packages/next-safe-action/src/hooks-utils.ts b/packages/next-safe-action/src/hooks-utils.ts index b770af8e..7021d48f 100644 --- a/packages/next-safe-action/src/hooks-utils.ts +++ b/packages/next-safe-action/src/hooks-utils.ts @@ -63,7 +63,7 @@ export const useExecuteOnMount = ( React.useEffect(() => { const t = setTimeout(() => { if (args.executeOnMount && !mounted.current) { - args.executeFn(args.executeOnMount.input); + args.executeFn(args.executeOnMount.input as S extends Schema ? InferIn : void); mounted.current = true; } }, args.executeOnMount?.delayMs ?? 0); diff --git a/packages/next-safe-action/src/hooks.types.ts b/packages/next-safe-action/src/hooks.types.ts index 486408db..f2b47d8c 100644 --- a/packages/next-safe-action/src/hooks.types.ts +++ b/packages/next-safe-action/src/hooks.types.ts @@ -6,10 +6,11 @@ import type { MaybePromise, Prettify } from "./utils.types"; * Type of base utils object passed to `useAction`, `useOptimisticAction` and `useStateAction` hooks. */ export type HookBaseUtils = { - executeOnMount?: { - input: S extends Schema ? InferIn : undefined; - delayMs?: number; - }; + executeOnMount?: (undefined extends S + ? { input?: undefined } + : { + input: S extends Schema ? InferIn : undefined; + }) & { delayMs?: number }; }; /** diff --git a/website/docs/types.md b/website/docs/types.md index cb7f3029..88862f2e 100644 --- a/website/docs/types.md +++ b/website/docs/types.md @@ -316,10 +316,11 @@ Type of base utils object passed to `useAction`, `useOptimisticAction` and `useS ```typescript export type HookBaseUtils = { - executeOnMount?: { - input: S extends Schema ? InferIn : undefined; - delayMs?: number; - }; + executeOnMount?: (undefined extends S + ? { input?: undefined } + : { + input: S extends Schema ? InferIn : undefined; + }) & { delayMs?: number }; }; ```