Why is the following monkey patch not allowed in Typescript?
const oldXHROpen = window.XMLHttpRequest.prototype.open
window.XMLHttpRequest.prototype.open = function (
method: string,
url: string
): void {
return oldXHROpen.apply(this, [method, url])
}
It gives the following error:
Argument of type '[string, string]' is not assignable to parameter of type '[method: string, url: string | URL, async: boolean, username?: string | null | undefined, password?: string | null | undefined]'.
Source has 2 element(s) but target requires 3.
However when looking at the definitions of open there is a method which only requires two arguments.
open(method: string, url: string | URL): void;