How does prototype extend on typescript?

后端 未结 4 800
情歌与酒
情歌与酒 2020-12-06 09:48

i extended function prototype but typescript doesn\'t recognize it.

Function.prototype.proc = function() {
  var args, target, v;
  var __slice = [].slice;
          


        
4条回答
  •  孤城傲影
    2020-12-06 10:29

    There is a Function interface in the standard typescript lib which declares the members of Function objects. You will need to declare proc as a member of that interface with your own add on like the following:

    interface Function {
        proc(...args: any[]): any;
    }
    

    This interface will need to be referenced from anywhere you intend to use 'proc'.

提交回复
热议问题