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 -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -