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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -