Closed cexbrayat closed 2 months ago
change @vue/runtime-core
to vue
will make it work, I had this issue with pnpm before due to how pnpm handle peers, but it seems with newest version npm also have the same issue 🤔
@RayGuo-ergou You're right that fixes it, but it used to support @vue/runtime-core
. I'm wondering if this no longer works on purpose (and if so it should maybe be mentioned in the changelog).
Some of the information here may be helpful.
https://github.com/vuejs/language-tools/issues/4501#issuecomment-2190384987
@cexbrayat Which older version work?
I've documented global components in the wiki. Please check and let me know if this approach works for you.
Thank you very much. It work now!
👍 Thanks for clarifying @davidmatter
I've documented global components in the wiki. Please check and let me know if this approach works for you.
That does not work for me unfortunately. I also tried solutions in https://github.com/vuejs/language-tools/issues/4501 and they did not work either.
The only thing that kinda worked was adding this to tsconfig.json
"vueCompilerOptions": {
"lib": "@vue/runtime-core",
},
And then use
declare module '@vue/runtime-core' {
interface GlobalComponents {
CustomComponent: typeof CustomComponent;
}
}
declare module 'vue'
causes it to not work with the tsconfig addition.
But when add the vueCompilerOptions
that causes errors everywhere in my site that uses (for example) a var foo = ref()
, to require adding the .value
when using it in the <template>
tags. The error it gives is Property 'foo' does not exist on type Ref
.
Just for reference, if I import the component locally to a file, the types are there no problem. It's only when registering it globally I have this problem.
Vue - Official extension or vue-tsc version
2.0.22
VSCode version
1.90.2
Vue version
3.4.30
TypeScript version
5.5.0
System Info
Steps to reproduce
Using a brand new create-vue project (see Stackblitz repro):
main.ts
createApp(App).component('HelloWorld', HelloWorld).mount('#app');
add it in
env.d.ts
forvue-tsc
:run
npm run type-check
:src/App.vue:14:8 - error TS2339: Property 'HelloWorld' does not exist on type '{}'.
14