TS2345: Argument of type “uncaughtException”

I’m unable to hook the process uncaught exception method built into node.js. Seems to me like this is a type definition issue.

In my testing you can bump @types/node but you end up breaking other dependancies and the app won’t start. There is an issue under the electron repo that has been open since 2017 😧.

electron/electron#9626

How to reproduce? Use this in the main.ts file and you’ll see TypeScript does not like the first argument.

process.on('uncaughtException', (err) => {
    // Do something here
});

1 possible answer(s) on “TS2345: Argument of type “uncaughtException”

  1. FWIW I’m going to be using this workaround for now.

    (process as NodeJS.EventEmitter).on('uncaughtException', (err) => {
    	console.log(err);
    });