Skip to content

Commit

Permalink
fix(types): allow omitting input in executeOnMount when it's undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Aug 14, 2024
1 parent 6e23887 commit b2c02f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/next-safe-action/src/hooks-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const useExecuteOnMount = <S extends Schema | undefined>(
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<S> : void);
mounted.current = true;
}
}, args.executeOnMount?.delayMs ?? 0);
Expand Down
9 changes: 5 additions & 4 deletions packages/next-safe-action/src/hooks.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<S extends Schema | undefined> = {
executeOnMount?: {
input: S extends Schema ? InferIn<S> : undefined;
delayMs?: number;
};
executeOnMount?: (undefined extends S
? { input?: undefined }
: {
input: S extends Schema ? InferIn<S> : undefined;
}) & { delayMs?: number };
};

/**
Expand Down
9 changes: 5 additions & 4 deletions website/docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ Type of base utils object passed to `useAction`, `useOptimisticAction` and `useS
```typescript
export type HookBaseUtils<S extends Schema | undefined> = {
executeOnMount?: {
input: S extends Schema ? InferIn<S> : undefined;
delayMs?: number;
};
executeOnMount?: (undefined extends S
? { input?: undefined }
: {
input: S extends Schema ? InferIn<S> : undefined;
}) & { delayMs?: number };
};
```
Expand Down

0 comments on commit b2c02f0

Please sign in to comment.