fix: typescript for script setup incorrect.
🐛 The bug As from version 0.28 we start support script setup. Test files for now only on javascript. In Typescript i found that ref variables not converted to value on template:

Our document still not mention about typescript type, since we use unplugin-vue2-script-setup for script setup, i try to add unplugin-vue2-script-setup/types to tsconfig.json. Result is ref variable turn to correct, but now all custom component turn to any.


This issue go away if use @vue/composition-api with unplugin-vue2-script-setup. So i think issue come from our package somehow
🛠️ To reproduce Steps to reproduce the behavior:
- create new nuxt project
- install
@nuxtjs/composition-api - write new custom component use script setup, like in screenshot
- see error about ref variable
- isntall
unplugin-vue2-script-setup. add tsconfig.json - create new Test component use script setup
- import Test component to main component
- see error when component inspected as ANY.
@TrungRueta Would you provide a reproduction via https://template.nuxtjs.org ? 🙏
@danielroe HiDaniel! Thank for look my issue <3
I created online sandbox follow you suggest, but sandbox only makesure my demo working on runtime while issue come from mismatch typescript type checking lead to volar incorrect spell checking.
so i deploy sandbox to a git , you can clone git, install use yarn then open page/index.vue . i leaved 2 variables and comment explain issue with type checking.
git
steps:
- clone git, install packages by yarn
- open by vscode, disable vetur and install volar extension
- open file
page/index.vue - see variable a (which is a ref use our package)
- see
aused in template. it correct in runtime (draw value true), but wrong in typescript checking (volar say it isRef<boolean>notboolean). - see
b. uncomment it on script and template, see volar say it ok . ( but runtime will failed, ofcouse because we are using vue 2, vue/reactivity is not meaning) - Now hover mouse to
<Test/>tag , you will see vscode show correct type of component. - open tsconfig.json. un comment types
"unplugin-vue2-script-setup/types". reload vscode, then go back to fileindex.vueand you will seeafor now understand correct isboolean. - now hover mouse to
<Test />component, you will see it become any. lost all type checking
Actually i spend hours to try install our package, unplugin-vue2-script-setup from antfu, compare d.ts files , finally i think i found issue:
- Volar extension for now is only one ext support
script setup, vetur still not - To use Volar with Vue2 + typescript, we need install
@vue/dom-runtimeas dev package and let it read by volar. -
nuxtjs/composition-apihas ownRef<T>which return byref(). - Look like vue 3 has same type
Ref<T>but different define. Volar only accept this Ref type to convert in template tag. - Add
"unplugin-vue2-script-setup/types"intsconfig.jsonhelp overwriteRef<T>type by antfu , but it also overwrite other typechecking . i guess between d.ts has breaking somewhere, it lead vscode typescript language parse wrong and give any to everywhere.
I hope my explains well enough to located problem.
Thank you again for wonderful project!!! Trung