Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TS annotation on v-model #4655

Closed
qgates opened this issue Sep 22, 2021 · 4 comments
Closed

Support TS annotation on v-model #4655

qgates opened this issue Sep 22, 2021 · 4 comments

Comments

@qgates
Copy link

qgates commented Sep 22, 2021

New issue repro of issue #4640. It was closed with fix that appears to address a different issue. Apologies for reposting.

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), when the attribute is specified in v-model. Type annotation would solve, and does do so with v-bind, but doesn't work with v-model. 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: vuejs/language-tools#512

@yyx990803
Copy link
Member

yyx990803 commented Sep 22, 2021

On the Volar side it seems its bundled compiler hasn't updated to incorporate d23fde3 yet. /cc @johnsoncodehk

@qgates
Copy link
Author

qgates commented Sep 22, 2021

It's not just a volar issue. I see a compilation error from vite and on the browser as well.

@yyx990803
Copy link
Member

I know. Turns out the TS transpiler used in SFC playground (sucrase) is able to parse invalid TS syntax generated by the compiler... but esbuild will throw an error in this case.

@qgates
Copy link
Author

qgates commented Sep 22, 2021

Essentially:

v-bind="var as string" works, as expected ie. clearing any ts2322 error where valid. But v-model="var as string" does not and complains about invalid expression syntax.

Thanks for looking into this 👍

@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants