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 -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -