Scipion
Scipion

Reputation: 11888

Vuejs: Typing $refs values

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 :)

Upvotes: 1

Views: 460

Answers (1)

steve16351
steve16351

Reputation: 5812

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.

Upvotes: 1

Related Questions