Open
Description
What happened?
I'm trying to create a group of custom checkboxes with some already checked by default. After reading the documentation of useField
, I tried to use initialValue
to an array including all the default values of the desired checkboxes.
Since my values are strings, the TS compiler throw an error asking for a string as initialValue
(to enforce the TValue
generic).
My problem is :
- if I use a
string[]
, it works as expected, but the compiler screams - if I use a
string
, it doesn't work (only one checkbox checked at a time) but the compiler is happy
Did I do something wrong or should the initialValue
be changed to TValue[]
in the case of checkboxes?
Reproduction steps
checkboxes.forEach(c => {
useField('my-checkboxes', undefined, {
type: 'checkbox',
checkedValue: c.value, // ← string
initialValue: checkboxes.filter(c => c.isDefault).map(c => c.value) // ← string[]
})
})
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
ts-plugin: Type 'string' is not assignable to type 'MaybeRefOrGetter<string[]> | undefined'. [2322]
Demo link
https://codesandbox.io/p/sandbox/vee-validate-custom-checkboxes-forked-18xffw
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels