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

typescript #11

Open
newbie78 opened this issue Nov 3, 2023 · 1 comment
Open

typescript #11

newbie78 opened this issue Nov 3, 2023 · 1 comment

Comments

@newbie78
Copy link

newbie78 commented Nov 3, 2023

why fieldValues: Partial<T> not fieldValues: T?

https://github.com/beizhedenglong/vue-hooks-form/blob/c7079209c7757a628432f0c7cc2e5c9dd0358797/src/useForm.ts#L148C36-L148C47

i'm got error like this

  public do(data: Partial<T>): void {
    thirdParty.process(T); //<-- Argument of type 'Partial<T>' is not assignable to parameter of type 'T'.
  }

tnx for great package!!

@beizhedenglong
Copy link
Owner

Hi @newbie78, only registered fields will available in submit handler. So the fieldValues passed in onSubmit is not identical with the form data. Do you have better ideas to express the type here? Feel free to create a PR!

const handleSubmit = (onSubmit: (fieldValues: Partial<T>) => any) => async (e?: Event) => {
    if (e) {
      e.preventDefault()
    }

    const error = await validateFields()
    if (!error) {
      onSubmit(getFieldValues())
    }
  }

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

2 participants