ts 如何添加prototype 屬性


如前文所示,在對應的index.d.ts/index.d.tsx中添加如下代碼:

 

interface Function {
  _toFixed(params: any): void;
}

Function.prototype._toFixed = function(params: any) {
  this.apply(this, params);
};

 

然后在index.ts/index.tsx中正常聲明即可:

bigNumber._toFixed = function (...arg: any) {
  const _this = Number(this);
  return new bigNumber(_this).isNaN() ? '0' : new bigNumber(_this.toFixed(...arg)).toString();
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM