将属性添加到 node.js 中的嵌套界面
Adding properties to a nested interface in node.js
在名为 'some-file.ts' 的文件中,我想这样做:
global.someProp = someVar;
而 global
是 NodeJS.Global
类型的预定义对象,在 node.d.ts.
中定义
如何让这个界面部分化?
我尝试了以下所有方法均无济于事:
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: Property 'someProp' does not exist on type 'Global'
我该如何解决?
我已经解决了。我不得不使用关键字 'declare' 如下:
declare namespace NodeJS{
interface Global {
base_dir: string;
}
}
在名为 'some-file.ts' 的文件中,我想这样做:
global.someProp = someVar;
而 global
是 NodeJS.Global
类型的预定义对象,在 node.d.ts.
如何让这个界面部分化?
我尝试了以下所有方法均无济于事:
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: Property 'someProp' does not exist on type 'Global'
我该如何解决?
我已经解决了。我不得不使用关键字 'declare' 如下:
declare namespace NodeJS{
interface Global {
base_dir: string;
}
}