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,
...args: any[]
): void {
return oldXHROpen.apply(this, [method, url, ...args])
}
It gives the following error:
Argument of type '[string, string, ...any[]]' is not assignable to parameter of type '[method: string, url: string | URL, async: boolean, username?: string | null | undefined, password?: string | null | undefined]'.
Target requires 3 element(s) but source may have fewer.
However when looking at the definitions of open
there is a method which only requires two arguments.
open(method: string, url: string | URL): void;