Home > Mobile >  Vuejs: Typing $refs values
Vuejs: Typing $refs values

Time:11-11

I have a Vuejs (3) project using Typescript. I'm trying to avoid relying on the type any when using $refs:

const el = (this.$refs['target'] as any).$el

It triggers the following warning:

warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Any idea what type I can use instead of any ?

EDIT: I don't want to disable my eslint rule :)

CodePudding user response:

As the ref refers to a Vue component (since you're using $el), you can use the interfaces Vue or VueConstructor which ship with Vue instead of any. This will give you access to the basic Vue properties of the component like $el, $data etc., though not specific methods and properties you've added yourself to the component.

This will keep ESLint happy as it's using something more specific than any.

  • Related