Adding properties to a nested interface in node.js
在名为\\'some-file.ts \\'的文件中,我要执行以下操作:
1
| global.someProp = someVar; |
,而global是类型为NodeJS.Global的预定义对象,该对象在node.d.ts.
中定义。
如何使该界面局部化?
我尝试了以下所有方法,但均无济于事:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| 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'
我该如何解决?
- 如何在node.js中使用全局变量的可能重复项?
-
@SteevePitis不!这是一个完全不同的问题。
-
然后尝试以另一种方式解释您的目标,因为我从未在js namespace中看到过这些关键字
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
-
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |
我已经解决了。我不得不按如下方式使用关键字" declare":
1 2 3 4 5
| declare namespace NodeJS{
interface Global {
base_dir: string;
}
} |