Skip to content

String Literal issue with function overloads  #8251

Closed
@folini

Description

@folini

TypeScript Version:

TypeScript 1.8.30.0

Issue

The following code (copy & paste from the TypeScript documentation) doesn't work. It generates a compiler error.

function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
function createElement(tagName: string): Element;
// ... more overloads ...

function createElement(tagName: string): Element {
    // ... code goes here ...
}

While, just moving the most general signature at the tip of the list will compile correctly.

function createElement(tagName: string): Element;
function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
// ... more overloads ...

function createElement(tagName: string): Element {
    // ... code goes here ...
}

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