Skip to content

Commit b2c02f0

Browse files
committedAug 14, 2024··
fix(types): allow omitting input in executeOnMount when it's undefined
1 parent 6e23887 commit b2c02f0

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed
 

‎packages/next-safe-action/src/hooks-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const useExecuteOnMount = <S extends Schema | undefined>(
6363
React.useEffect(() => {
6464
const t = setTimeout(() => {
6565
if (args.executeOnMount && !mounted.current) {
66-
args.executeFn(args.executeOnMount.input);
66+
args.executeFn(args.executeOnMount.input as S extends Schema ? InferIn<S> : void);
6767
mounted.current = true;
6868
}
6969
}, args.executeOnMount?.delayMs ?? 0);

‎packages/next-safe-action/src/hooks.types.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import type { MaybePromise, Prettify } from "./utils.types";
66
* Type of base utils object passed to `useAction`, `useOptimisticAction` and `useStateAction` hooks.
77
*/
88
export type HookBaseUtils<S extends Schema | undefined> = {
9-
executeOnMount?: {
10-
input: S extends Schema ? InferIn<S> : undefined;
11-
delayMs?: number;
12-
};
9+
executeOnMount?: (undefined extends S
10+
? { input?: undefined }
11+
: {
12+
input: S extends Schema ? InferIn<S> : undefined;
13+
}) & { delayMs?: number };
1314
};
1415

1516
/**

‎website/docs/types.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@ Type of base utils object passed to `useAction`, `useOptimisticAction` and `useS
316316
317317
```typescript
318318
export type HookBaseUtils<S extends Schema | undefined> = {
319-
executeOnMount?: {
320-
input: S extends Schema ? InferIn<S> : undefined;
321-
delayMs?: number;
322-
};
319+
executeOnMount?: (undefined extends S
320+
? { input?: undefined }
321+
: {
322+
input: S extends Schema ? InferIn<S> : undefined;
323+
}) & { delayMs?: number };
323324
};
324325
```
325326

0 commit comments

Comments
 (0)
Please sign in to comment.