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

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Java JSoup error fetching URL -

webstorm - PhpStorm file cache conflict with TypeScript compiler -