Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
迭代node.js进程事件时,没有重载与此调用匹配_Node.js_Typescript - Fatal编程技术网

迭代node.js进程事件时,没有重载与此调用匹配

迭代node.js进程事件时,没有重载与此调用匹配,node.js,typescript,Node.js,Typescript,我使用的库在默认情况下添加了uncaughtException和unhandledRejection侦听器。我想删除它们 这是我的密码: ["unhandledRejection", "uncaughtException"].forEach((eventName) => process .listeners(eventName) .map((handler) => process.off(eventName, handler)) ); TypeScript给

我使用的库在默认情况下添加了
uncaughtException
unhandledRejection
侦听器。我想删除它们

这是我的密码:

["unhandledRejection", "uncaughtException"].forEach((eventName) =>
  process
    .listeners(eventName)
    .map((handler) => process.off(eventName, handler))
  );
TypeScript给了我以下错误:

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'Signals'.
查看
@types/node
中包含的
global.d.ts
,我可以看到声明如下所示:

listeners(event: "uncaughtException"): UncaughtExceptionListener[];
listeners(event: "unhandledRejection"): UnhandledRejectionListener[];
listeners(event: Signals): SignalsListener[];
因此,TypeScript编译器似乎认为我希望使用
事件:信号
函数签名。这不是我想要的


有没有办法告诉TypeScript我想用哪一个?或者以其他方式解决问题?

如果查看
未处理的RejectionListener
您会发现它的定义如下:

type UnhandledRejectionListener = (reason: {} | null | undefined, promise: Promise<any>) => void;
type SignalsListener = (signal: Signals) => void;
typescript假定您想要使用
SignalsListener
类型

要使其工作,您必须传递类型为
UnhandledRejectionListener