[Vuejs]-How to annotate a variable in Vue as a Vue component when using Typescript?

0👍

in vue+vscode ecosystem, now typescript cannot infer type from template declaration. (maybe it will be)

and for $refs[xxx]:

Type ‘Vue | Element | Vue[] | Element[]’ is not assignable to type ‘Vue’.

you can use type assertions instead:

const component = this.$refs["component"] as typeof MyComponent;

Leave a comment