How does prototype extend on typescript?

后端 未结 4 790
情歌与酒
情歌与酒 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条回答
  •  萌比男神i
    2020-12-06 10:15

    Like this:

    declare global {
        interface Function {
            proc() : any;
        }
    }
    

    Without 'declare global' it doesn't work.

    That's how module augmentation works in recent TypeScript versions. Check out the documentation and scroll down to the Module augmentation section.

提交回复
热议问题