[英]Is there a good way to extend @types/node/index.d.ts
process._getActiveHandles()
produces an error because not everything was published in @type/nodes/index.d.ts
. process._getActiveHandles()
产生错误,因为并非所有内容都发布在@type/nodes/index.d.ts
。 I have node v8.11.1 and I used npm install @types/node@9.6.2
. 我有节点v8.11.1,我使用了
npm install @types/node@9.6.2
。 Should I stop using npm's @types and edit my own copy? 我应该停止使用npm的@types并编辑自己的副本吗?
The @types/node@12.7.5
does not have it in globals.d.ts
either. @types/node@12.7.5
在globals.d.ts
也没有。
(<any>process)._getActiveHandles()
of course ignores the error, but I don't want to lose the typo-checking. (<any>process)._getActiveHandles()
当然会忽略该错误,但我不想丢失拼写检查。
_getActiveHandles()
is just one case. _getActiveHandles()
仅是一种情况。
You should be able to add custom types to the existing node types. 您应该能够将自定义类型添加到现有节点类型。 With something like:
用类似的东西:
declare global {
namespace NodeJS {
interface Process {
_getActiveHandles(arg: number): boolean;
}
}
}
process._getActiveHandles = (arg) => !!arg;
const result = process._getActiveHandles(1)
console.log(result)
Thanks skovy. 谢谢斯科维。 (I could not get code into the comment.)
(我无法将代码添加到注释中。)
Placing this in a separate ts file allowed access to the existing function without complaints from both tsc and Visual Code (although tsc might never have complained???): 将其放在单独的ts文件中可以访问现有功能,而不会受到tsc和Visual Code的抱怨(尽管tsc可能从未抱怨过??):
declare global {
namespace NodeJS {
interface Process {
_getActiveHandles(): any[];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.