【发布时间】:2020-07-01 22:47:46
【问题描述】:
Typescript:如何使用原型为函数添加类型?
interface Fool {
greet(): any;
}
function Fool(name: string) {
this.name = name;
}
Fool.prototype.greet = function() {
console.log(`Fool greets ${this.name}`);
};
Fool('Joe').greet();
`Property 'greet' does not exist on type 'void'.`;
【问题讨论】:
-
你错过了
new吗? -
你为什么不使用类呢?
标签: node.js typescript ts-node