Subscribe on changes!

Support TS annotation on v-model

avatar
Sep 21st 2021

What problem does this feature solve?

An object with attributes of union type throws ts2322 in Volar when supplied to v-model for textarea, input (and others). v-bind allows TS type annotation on attributes, clearing the error, but v-model does not. Ergo the only current workaround is to use a v-bind/@change combo where TS annotations can be used.

Example usecase:

interface MyType {
  data: string|Date,
}

Template:

<textarea v-model="arr[index].data as string" ...

where arr is a MyType[]

More info: https://github.com/johnsoncodehk/volar/issues/512

avatar
Sep 21st 2021

@yyx990803 maybe I'm missing something but I still see errors in template compilation and Volar with the above?