【发布时间】:2017-02-19 18:10:25
【问题描述】:
在一个名为“some-file.ts”的文件中,我想这样做:
global.someProp = someVar;
而global 是在node.d.ts 中定义的NodeJS.Global 类型的预定义对象。
我怎样才能使这个界面局部化?
我尝试了以下所有方法均无济于事:
interface Global {
someProp: string;
}
global.someProp = someVar;
interface NodeJS.Global {
someProp: string;
}
global.someProp = someVar;
namespace NodeJS{
interface Global {
someProp: string;
}
}
global.someProp = someVar;
我不断得到:
TS339:“全局”类型上不存在属性“someProp”
我该如何解决?
【问题讨论】:
-
@SteevePitis 不!这是一个完全不同的问题。
-
然后尝试用不同的方式解释你的目标,因为我从未在 js
namespace&interface中看到那些关键字 -
@SteevePitis 我的问题完全是关于 TypeScript 和使用部分接口,这是 TypeScript 的一个特性。您提到的问题根本与 TypeScript 无关!
-
好的,在你的标题中说出来 ;)
标签: node.js oop typescript interface partial-classes