相关疑难解决方法(0)

原型如何在打字稿上扩展?

我扩展了函数原型但是typescript无法识别它.

Function.prototype.proc = function() {
  var args, target, v;
  var __slice = [].slice;
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  target = this;
  while (v = args.shift()) {
    target = target(v);
  }
  return target;
};
// generated by coffee-script

var foo: (number) => (string) => number
  = (a) => (b) => a * b.length;
console.log(foo.proc("first", "second"))
Run Code Online (Sandbox Code Playgroud)

结果:tsc -e

The property 'proc' does not exist on value of type 'Function'
Run Code Online (Sandbox Code Playgroud)

我该如何扩展这个对象?

javascript typescript

18
推荐指数
2
解决办法
8409
查看次数

标签 统计

javascript ×1

typescript ×1