-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
What happened?
When using path containing arrays notation (array[${0}].something) with setFieldValue value type is always set to never.
Everything works as expected, it's just a typing issue.
Reproduction steps
-
Create a dummy test component like:
<script lang="ts" setup> import * as z from 'zod' import { useForm } from 'vee-validate' const schema = z.object({ value: z.string(), // will test on this array array: z.array(z.object({ name: z.string(), })), }) const { setFieldValue, values } = useForm({ validationSchema: schema, }) function doSomething() { // this resolves to `string` as expected setFieldValue(`value`, 'foobar') // this resolves to `{ name: string }[]` as expected setFieldValue(`array`, [{ name: 'foo' }]) // this types resolve to `never`, whereas it should resolve to `{ name: string }` setFieldValue(`array[${0}]`, { name: 'qux' }) // this types resolve to `never`, whereas it should resolve to `string` setFieldValue(`array[${2}].name`, 'baz') } </script> <template> <div> <button @click="doSomething"> Do something </button> <pre>{{ values }}</pre> </div> </template>
-
Clicking on "Do something" button should resolve as expected:
{ "value": "foobar", "array": [ { "name": "qux" }, null, { "name": "baz" } ] }
Version
Vue.js 3.x and vee-validate 5.x
What browsers are you seeing the problem on?
- Firefox
- Chrome
- Safari
- Microsoft Edge
Relevant log output
Demo link
https://stackblitz.com/edit/vitejs-vite-getzynyz?file=src%2FApp.vue&terminal=dev
Code of Conduct
- I agree to follow this project's Code of Conduct
vladimir-econom, newfeeder, richardpolzer, aottoh and johannesspohr
Metadata
Metadata
Assignees
Labels
No labels