Date对象添加方法出错

interface Date{
      completion():any
    }Date.prototype.completion=function(time){        return time<10?'0'+time:time;
      };

报错completion does not exist on type date prototype ‘Date’


慕森卡
浏览 500回答 1
1回答

蛊毒传说

你在接口里定义的&nbsp;completion():any&nbsp;是没有参数的,但是给 prototype.completion 赋值的那个函数是带一个参数的。interface&nbsp;Date&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;completion(time:any):&nbsp;any}Date.prototype.completion&nbsp;=&nbsp;function&nbsp;(time)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;time&nbsp;<&nbsp;10&nbsp;?&nbsp;'0'&nbsp;+&nbsp;time&nbsp;:&nbsp;time; };通过,Typescript 版本$&nbsp;tsc&nbsp;-v Version&nbsp;2.0.10
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript