typescript variable number of parameters in function interface definition 0.9.5

后端 未结 1 1142
长情又很酷
长情又很酷 2021-02-08 12:21

I have this scenario, the file is t.ts:

interface Itest{
   (event: any, ...args: any[]):any;
   }

   var t1: Itest = function (testparam) { return true;};
   v         


        
1条回答
  •  情书的邮戳
    2021-02-08 13:25

    Since rest parameters are optional, you need to make them optional in your functions as well:

       interface Itest{
       (event: any, ...args: any[]):any;
       }
    
       var t1: Itest = function (testparam?) { return true;};
       var t2: Itest = function (testparam?, para1?) { return true; };
       var t3: Itest = function (testparam?, para1?, para2?) { return true; };
    
    
       interface Itest2 {
         (event: any, para1,...args: any[]): any;
       }
       var t4: Itest2 = function (testparam, para1) { return true; };
       var t5: Itest2 = function (testparam, para1, para2?) { return true; };
    

    This is new in TS0.9.5

    0 讨论(0)
提交回复
热议问题