Typescript String Literal Types not working in function overloading -
according typescript documentation (look string literal types section), 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 ... }
when run code, or more meaningful variation, on typescript playground, or on visual studio, following error:
specialized overload signature not assignable non-specialized signature.
any suggestion? came error after trying implement similar on own code.
did try start 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 { /* ... */ }
```
Comments
Post a Comment