给定接口
interface FooWithBar {
():void;
bar():void;
}
我如何编写实现?
function foo(){
}
foo.bar = function(){
};
不起作用,因为它会引发错误,“类型'() => void 上不存在属性'bar'”。但是,如果我声明的类型foo
是FooWithBar
```` var foo: FooWithBar = function () {
};
foo.bar = function () {
};
````
我收到另一个错误,“类型'() => void'不可分配给类型'FooWithBar'。类型'() => void'中缺少属性'bar'”。
我该如何解决这个catch-22?