Skip to content

Commit

Permalink
fix arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Oct 8, 2024
1 parent 7eafa1e commit 1f3debf
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/utils/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function setFormErrors(
export type SubmitFormOptions<
QueryArg extends object,
ResultType,
FormValues extends QueryArg,
FormValues,
> = Partial<{
clean: (values: FormValues) => QueryArg
exclude: string[]
Expand All @@ -52,10 +52,7 @@ export type SubmitFormOptions<
finally: (values: FormValues, helpers: FormikHelpers<FormValues>) => void
}>

export type SubmitFormHandler<
QueryArg extends object,
FormValues extends QueryArg,
> = (
export type SubmitFormHandler<FormValues> = (
values: FormValues,
helpers: FormikHelpers<FormValues>,
) => void | Promise<any>
Expand All @@ -65,9 +62,26 @@ export function submitForm<
ResultType,
FormValues extends QueryArg,
>(
trigger: TypedMutationTrigger<ResultType, QueryArg, any>,
options?: Omit<SubmitFormOptions<QueryArg, ResultType, FormValues>, "clean">,
): SubmitFormHandler<FormValues>

export function submitForm<QueryArg extends object, ResultType, FormValues>(
trigger: TypedMutationTrigger<ResultType, QueryArg, any>,
options?: Omit<
SubmitFormOptions<QueryArg, ResultType, FormValues>,
"clean"
> & {
clean: NonNullable<
SubmitFormOptions<QueryArg, ResultType, FormValues>["clean"]
>
},
): SubmitFormHandler<FormValues>

export function submitForm<QueryArg extends object, ResultType, FormValues>(
trigger: TypedMutationTrigger<ResultType, QueryArg, any>,
options?: SubmitFormOptions<QueryArg, ResultType, FormValues>,
): SubmitFormHandler<QueryArg, FormValues> {
): SubmitFormHandler<FormValues> {
const {
clean,
exclude,
Expand All @@ -77,7 +91,7 @@ export function submitForm<
} = options || {}

return (values, helpers) => {
let arg: QueryArg = clean ? clean(values) : values
let arg = clean ? clean(values) : (values as unknown as QueryArg)

if (exclude) arg = excludeKeyPaths(arg, exclude)

Expand Down

0 comments on commit 1f3debf

Please sign in to comment.