process._getActiveHandles()
产生错误,因为并非所有内容都发布在@type/nodes/index.d.ts
中。
我有节点v8.11.1,并且使用了npm install @types/node@9.6.2
。
我应该停止使用npm的@types并编辑自己的副本吗?
@types/node@12.7.5
中也没有globals.d.ts
。
(<any>process)._getActiveHandles()
当然会忽略该错误,但我不想丢失错字检查。
_getActiveHandles()
仅是一种情况。
答案 0 :(得分:1)
您应该能够将自定义类型添加到现有节点类型。像这样:
declare global {
namespace NodeJS {
interface Process {
_getActiveHandles(arg: number): boolean;
}
}
}
process._getActiveHandles = (arg) => !!arg;
const result = process._getActiveHandles(1)
console.log(result)
答案 1 :(得分:0)
感谢skovy。 (我无法在注释中添加代码。)
将此内容放置在单独的ts文件中,可以访问现有功能,而不会受到tsc和Visual Code的投诉(尽管tsc可能从未抱怨过?):
{{1}}