According to TypeScript documentation (look for the String Literal Types section), the following code should work on TypeScript:
function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
// ... more overloads ...
function createElement(tagName: string): Element {
// ... code goes here ...
}
Specialized overload signature is not assignable to any non-specialized signature.
Did you try to start with a non specialized signature?
function createElement(tagName: string): Element;
function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
// ... more overloads ...
function createElement(tagName: string): Element { /* ... */ }
```