I have the following setup of interfaces
and types
:
export interface MyEventMap extends ElementEventMap {
'loaded': Event
}
export type MyEventsTypes = {
[key in keyof (HTMLElementEventMap & MyEventMap)]?: (e: Event) => void
}
export interface ObectInterface {
events?: MyEventsTypes
}
When I try and use the ObjectInterface
, within the loaded
function I get this error:
Property 'textContent' does not exist on type 'MyEventsTypes'.
How can I make it so that typescript knows that this
is bound to an HTMLElement
and not MyEventsTypes
? When I compile my code, and loaded
runs, this.textContent
works just fine, and displays the text.
<ObjectInterface>{
events: {
loaded() {
console.log(this.textContent)
}
}
}