hebrerillo
Coder
Hello there!
I am trying to catch the 'onHashChange' event in TypeScript and to work with the new URL. Here is the code:
However, the compiler gives this error:
I tried many things and searched a lot in the net but found nothing.
Can someone please help me???
Thank you so much!!!
I am trying to catch the 'onHashChange' event in TypeScript and to work with the new URL. Here is the code:
JavaScript:
window.addEventListener('hashchange', function(event: HashChangeEvent) {
console.log(event);
});
However, the compiler gives this error:
Code:
No overload matches this call.
Overload 1 of 2, '(type: "hashchange", listener: (this: Window, ev: Event) => any, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
Argument of type '(this: Window, event: HashChangeEvent) => void' is not assignable to parameter of type '(this: Window, ev: Event) => any'.
Types of parameters 'event' and 'ev' are incompatible.
Type 'Event' is missing the following properties from type 'HashChangeEvent': newURL, oldURL
Overload 2 of 2, '(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
Argument of type '(this: Window, event: HashChangeEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
Type '(this: Window, event: HashChangeEvent) => void' is not assignable to type 'EventListener'.
Types of parameters 'event' and 'evt' are incompatible.
Type 'Event' is not assignable to type 'HashChangeEvent'.
I tried many things and searched a lot in the net but found nothing.
Can someone please help me???
Thank you so much!!!
Last edited: