Question about field.state.value typing with Vue
Hi, I'm new to this library and fairly new to TS, so please excuse the probably silly question. However, I've followed the async initial values example for Vue from the docs, and I'm finding that the TS linter is complaining because the possible types of the field.state.value across all fields is shown as all the types contained in the type I passed to useForm. However, for each field the types are limited by the model-value prop for the respective input/control type. I managed to fix this yesterday, I think by passing <Partial<myFormType>> to useForm, but this isn't working now I've added some more fields. I don't know how I've broken it and hope it's an easy fix 🙂 Thanks in advance for any help, and thanks for the library.

6 Replies
quickest-silverOP•8mo ago

quickest-silverOP•8mo ago
So I guess I'm wondering if inside the form.Field element, with a correct name prop, field.state.value should only have the specific types for that field shown?
update: I solved it before by having one of the field types defined as 'any', which presumably short-circuits the check that is failing. I don't feel like it's the right solution though, as I'd like to properly type all of the field values.
update: I've now fixed it by using :model-value="field.state.value as string", etc, to assert the type. Is this the right way to do it? Thanks.
deep-jade•8mo ago
There's currently a bug in our Vue adapters you may be running into
deep-jade•8mo ago
GitHub
[WIP] [FEAT] Allow returning anything in a validator, not just a st...
This PR allows you to return non-string values from validators:
<form.Field name="password" validators={{onChange: () => ({hasUppercase: false, hasLowercase: true}) ...
deep-jade•8mo ago
It'll be fixed here
quickest-silverOP•8mo ago
ok brilliant, thanks very much!