Skip to content

.call selects the wrong overload, resulting in ts2554Β #63152

@joshcartme

Description

@joshcartme

πŸ”Ž Search Terms

I search for .call overload, this might be related to #29789 but I'm not sure

πŸ•— Version & Regression Information

  • I looked back through some versions to 4.x on the playground and this was present in those I checked

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260217#code/MYewdgzgLgBAHgCwE4HkAOBTMMC8MAaAsgDIASUUaAShgI4CuG0AdGkiFBwJ6bMiZgA3ACgiZCtTqMWbDt178suGADN6YYFACW4GIrAAKALYYoCEABMANDHpIANgEoYAb2EBIJKbvZEqAcam5ta2Do4iAL4ioiTklDQMTFCs7JxQPBh8AspqGtq6+oFmljZ2Tq4eXlA+8MjoWMzAAIb29gZmWhA2JsUhZeHCUcJAA

πŸ’» Code

// this passes
const xhrOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function open(method, url) {
	return xhrOpen(method, url);
};

// the use of `.call` reports "Expected 4-6 arguments, but got 3.(2554)"
XMLHttpRequest.prototype.open = function open(method, url) {
	return xhrOpen.call(this, method, url); // error on this line
};

πŸ™ Actual behavior

.call reports "Expected 4-6 arguments, but got 3.(2554)"

πŸ™‚ Expected behavior

The use of .call infers that it matches the first overload the same way this is inferred without .call

From https://raw.githubusercontent.com/microsoft/TypeScript-DOM-lib-generator/refs/heads/main/baselines/dom.generated.d.ts open is typed as:

/**
 * The XMLHttpRequest method **`open()`** initializes a newly-created request, or re-initializes an existing one.
 *
 * [MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/open)
 */
open(method: string, url: string | URL): void;
open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void;

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions