tjinauyeung / svelte-forms-lib

📝. A lightweight library for managing forms in Svelte
https://svelte-forms-lib-sapper-docs.now.sh/
MIT License
603 stars 59 forks source link

Type Definition file presents incorrect type for the custom validation function #157

Open Eosis opened 2 years ago

Eosis commented 2 years ago

While working on a form with a custom validation function, I encountered behaviour inconsistent with the type declaration file: The validate function is typed as taking the entire form props as an argument, when in reality it only receives the latest updated value. See below:

https://github.com/tjinauyeung/svelte-forms-lib/blob/7df1b1df4f02c5ff512e2542c879056ac2d8138d/lib/index.d.ts#L6-L12

https://github.com/tjinauyeung/svelte-forms-lib/blob/7df1b1df4f02c5ff512e2542c879056ac2d8138d/lib/create-form.js#L90-L100

A quick fix would be to set the type of the argument to validate to be Partial<Inf>.

Longer term, it would probably be preferable to return the full type (all the values in the form) to the custom validate function, as this would allow behaviour such as ensuring validity of a form where two of the fields are linked, which currently is not possible.