javascript - Implementing function overloading -


since javascript not support function overloading typescript not support it. valid interface declaration:

// function overloading in interface  interface ifoo{     test(x:string);     test(x:number); }  var x:ifoo; x.test(1); x.test("asdf"); 

but how can implement interface. typescript not allow code:

// function overloading in interface  interface ifoo{     test(x:string);     test(x:number); }  class foo implements ifoo{     test(x:string){      }     test(x:number){      } } 

try it

function overloading in typescript done this:

class foo implements ifoo {     test(x: string);     test(x: number);     test(x: any) {         if (typeof x === "string") {             //string code         } else {             //number code         }     } } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -