You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've defined a ref<MyInterface>() as initialValues that will be updated with loaded data in onMounted.
Unfortunately the form-values are not inferred correctly.
Please take a look here for demonstration:
interface Person {
name: string;
age: number;
}
const initialValues = ref<Person>();
const form = useForm({ initialValues });
onMounted(async () => {
initialValues.value = { age: 45, name: 'Mike' }; // loaded via request
});
// form.values expected to be `{ name: string; age: number; } | undefined - but is `Record<string, any>`
Can form.values be inferred somehow by updating the typings?
Reproduction steps
Use the Code-Sample above
Inspect form.values in VS-Code
Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Firefox
Chrome
Safari
Microsoft Edge
Relevant log output
No response
Demo link
FYI: Unfortunately my Stackblitz-Demo (from below) is not working because of
Limited TypeScript Support to experience the issue
does not update form-values, which is really weird
Yep, this is a bug, I aim to solve this in #4064 as I discovered it there while working on the PR. I'm hard stuck with some things in Yup but should be tagged soon.
Thanks @logaretm for those refactorings.
If I see it right, now I have to define a Partial-Ref for initialValues with an empty object, correct? const initialValues = ref<Person>() --> ref<Partial<Person>>({});
But when I do it that way, the form-values are defined as required as you can see here, but age could be undefined:
Should NOT be required to be a partial ref, could be a partial of a non-ref. It is possible that value inference is not picking it up correctly since a lot of generics keep tossing the type around. will take a look over the weekend.
What happened?
I've defined a
ref<MyInterface>()
as initialValues that will be updated with loaded data inonMounted
.Unfortunately the form-values are not inferred correctly.
Please take a look here for demonstration:
Can
form.values
be inferred somehow by updating the typings?Reproduction steps
form.values
in VS-CodeVersion
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Relevant log output
No response
Demo link
FYI: Unfortunately my Stackblitz-Demo (from below) is not working because of
https://stackblitz.com/edit/vee-validate-v4-starter-composition-example-zka5nq?file=src/App.vue
Code of Conduct
The text was updated successfully, but these errors were encountered: