我正在学习Typescript,我想利用原型的优势。我还使用了一个外部库,它有一个类型文件。
到目前为止,这是可行的。
// main.ts
declare class Foo {}
interface Foo {
bar(): void;
}
Foo.prototype.bar = function() {}但是,声明在不同的文件中,所以当我尝试这样做时,它不起作用。
foo.d.ts:
declare class Foo {}main.ts:
interface Foo {
bar(): void;
}
Foo.prototype.bar = function() {}main.ts: TS6133:'Foo‘已声明但从未使用过。
main.ts: TS2339:属性‘main.ts’在类型'Foo‘上不存在。
我是不是遗漏了编译标志或别的什么?当我在单独的文件中时,我如何让它被编译?
发布于 2016-12-11 17:17:52
您需要使用module augmentation
// main.ts
import { Foo } from "./foo";
Foo.prototype.bar = function() {}https://stackoverflow.com/questions/41082505
复制相似问题