Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to augment `ElementAttrs<HTMLAttributes>` interface in Vue?

I'm using Vue 3 with TSX, how to augment the ElementAttrs<HTMLAttributes> interface, so I could do the following without getting type errors?

import { defineComponent } from 'vue'

export default defineComponent({
  setup() {
    //                                👇 ts complains
    return () => <div class='v-table' vLoading={true}></div>
  },
})

The error I got is:

Type '{ class: string; vLoading: boolean; }' is not assignable to type 'ElementAttrs<HTMLAttributes>'.

Property 'vLoading' does not exist on type 'ElementAttrs<HTMLAttributes>'.ts(2322)
like image 649
Wenfang Du Avatar asked Oct 21 '25 16:10

Wenfang Du


1 Answers

I've figured this out:

// Import an entire module for side effects only, without importing anything.
// This runs the module's global code but doesn't actually import any values.
import 'vue'

declare module 'vue' {
  interface HTMLAttributes {
    vLoading?: unknown
  }
}
like image 131
Wenfang Du Avatar answered Oct 23 '25 07:10

Wenfang Du



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!