Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep generic aspect of SubmissionHandler in FormSlotProps #4845

Open
quentinboudinel opened this issue Aug 26, 2024 · 0 comments
Open

Keep generic aspect of SubmissionHandler in FormSlotProps #4845

quentinboudinel opened this issue Aug 26, 2024 · 0 comments

Comments

@quentinboudinel
Copy link

quentinboudinel commented Aug 26, 2024

Is your feature request related to a problem? Please describe.

In the following scenario:

<script setup lang="ts">
import type { MyGenericObject } from '@/types' // MyGenericObject extends GenericObject

function onSubmit(values: MyGenericObject) {}
</script>

<template>
  <Form v-slot="{ handleSubmit }">
    <form @submit.prevent="handleSubmit($event, onSubmit)"></form>
  </Form>
</template>

My type checker doesn't agree with me defining the values param of the onSubmit function param as anything else than GenericObject and this because FormSlotProps is not generic and its property handleSubmit is defined strictly as SubmissionHandler (with no generic params)

Describe the solution you'd like

I would like to be able to define my submission handler as previously described without type checker error.

Describe alternatives you've considered

I think redefining

type FormSlotProps = UnwrapRef<Pick<FormContext, 'meta' | 'errors' | 'errorBag' | 'values' | 'isSubmitting' | 'isValidating' | 'submitCount' | 'validate' | 'validateField' | 'handleReset' | 'setErrors' | 'setFieldError' | 'setFieldValue' | 'setValues' | 'setFieldTouched' | 'setTouched' | 'resetForm' | 'resetField' | 'controlledValues'>> & {
    handleSubmit: (evt: Event | SubmissionHandler, onSubmit?: SubmissionHandler) => Promise<unknown>;
    submitForm(evt?: Event): void;
    getValues<TValues extends GenericObject = GenericObject>(): TValues;
    getMeta<TValues extends GenericObject = GenericObject>(): FormMeta<TValues>;
    getErrors<TValues extends GenericObject = GenericObject>(): FormErrors<TValues>;
};

to include generic params should do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant