vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 429 forks source link

Typing $refs on third party components #573

Open standuprey opened 2 years ago

standuprey commented 2 years ago

I figured a way to type $refs on third party components

In my case, I want to know the height of a v-list-item-group (vuetify):

  <v-list-item-group
    :value="value"
    ref="container"
  >...</v-list-item-group>
  $refs!: { container: Vue };

This works fine until I try to get this.$refs.container.$el.offsetHeight it complains with

Property 'offsetHeight' does not exist on type 'Element'

Is that a bug in Element's type?

jmroon commented 2 years ago

You need to make a type assertion to HTMLElement.