TypeScript - Vue'da `ElementAttrs` arayüzünü nasıl artırabilirim?
Vue 3'ü TSX ile kullanıyorum, ElementAttrs<HTMLAttributes> arayüzünü nasıl genişletebilirim, böylece aşağıdakileri yaparken tip hatası almayayım?
import { defineComponent } from 'vue'
export default defineComponent({
setup() {
// 👇 ts complains
return () => <div class='v-table' vLoading={true}></div>
},
})
Aldığım hata şudur:
Type '{ class: string; vLoading: boolean; }' is not assignable to type 'ElementAttrs<HTMLAttributes>'.
Property 'vLoading' does not exist on type 'ElementAttrs<HTMLAttributes>'.ts(2322)
Cevap #1
Bunu çözdüm:
// 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
}
}
