What TypeScript type to use for a variable to contain a mounted Vue Component #13808
Replies: 1 comment 2 replies
-
Hi @ejohanson-vi3, try using The root cause is likely a TypeScript type conflict. You probably have two slightly different versions of Vue's types floating around in your
Your import { ComponentPublicInstance } from "vue"
export class MyClass {
private vueComponent: ComponentPublicInstance
public constructor(vueComponent: ComponentPublicInstance) {
this.vueComponent = vueComponent
}
} Hope it helps |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to pass a mounted Vue component to a TypeScript class method. The question is, what type do I use for the parameter? For a long time, I used "InstanceType" and it worked fine. But I've recently updated a lot of settings and versions, and now suddenly this type no longer works, but produces the error during TypeScript compilation:
It's very easy to reproduce this with the two source files shown below: A Vue.JS component file, and a TypeScript file. When viewing the Vue component file in the code editor, it shows the red underline error on the call to
new Myclass(this)
. And you get the error shown above when running "npm run build" on the project.File HomeView.vue:
File MyClass.ts:
So what is the correct TypeScript type to use to accept a Vue component as a parameter?
Beta Was this translation helpful? Give feedback.
All reactions