Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript doesn't check multiple method definitions correctly #2442

Closed
toothbrush7777777 opened this issue Mar 20, 2015 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@toothbrush7777777
Copy link

Example

function test(element: HTMLElement);
function test(selector: string);
function test(elementOrSelector: HTMLElement|string) {
    var element: HTMLElement, initialText = '';

    if (typeof elementOrSelector === 'string') {
        element = <any>document.querySelector(elementOrSelector);
    } else if (elementOrSelector instanceof HTMLElement) {
        element = elementOrSelector;
    } else {
        throw new TypeError('elementOrSelector must be either an HTML element or a CSS selector (e.g. passing document.getElementById("element") and "#element" is equivalent)');
    }
}

function replace(element: HTMLElement);
function replace(selector: string);
function replace(elementOrSelector: HTMLElement|string) {
    return test(elementOrSelector);
}

TypeScript throws an error on line 18 (return test(elementOrSelector);):

Argument of type 'string | HTMLElement' is not assignable to parameter of type 'string'. Type 'HTMLElement' is not assignable to type 'string'.
(parameter) elementOrSelector: string | HTMLElement
@RyanCavanaugh
Copy link
Member

Same issue as in #1805.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 20, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants