Vue: Custom methods through vue-class-component are not recognized with $ref

Created on 23 Jan 2017  ·  3Comments  ·  Source: vuejs/vue

Hi all,

I have got an error message like this:

error TS2339: Property 'show' does not exist on type 'Element | Vue | Vue[] | Element[]'

It points to a line like this:

this.$refs['myDialog'].show()

This show is a method implemented in TypeScript using vue-class-component. It is in a class that extends Vue. I located the line in ./types/vue.d.ts here.

I guess it should be modified using generics like this:

readonly $refs: { [key: string]: [V extends Vue] | Element | Array<V extends Vue> | Array<Element>};

But it doesn't work by just doing that.

Does anyone know how to do it right?

Thanks!

Most helpful comment

You either need cast it <YourComonent>this.$refs or reify $refs.
https://github.com/HerringtonDarkholme/av-ts/wiki/FAQ#2-property-reification

All 3 comments

You either need cast it <YourComonent>this.$refs or reify $refs.
https://github.com/HerringtonDarkholme/av-ts/wiki/FAQ#2-property-reification

your descript don't let me know how to fix this problem. show the answer step by step, pls.

really confuse about ts+ vue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RashadSaleh picture RashadSaleh  ·  51Comments

alenyu picture alenyu  ·  43Comments

ferry77 picture ferry77  ·  67Comments

yyx990803 picture yyx990803  ·  210Comments

smolinari picture smolinari  ·  116Comments