TypeScript types by using Node multiprocessing are falsly assumed undefined

146 Views Asked by At

Using TypeScript to write a multiprocessing Node application I see the problem that e.g. this code is creating a compiler error although it's definitely working:

// main.ts
import * as child from 'child_process';
child.fork('my_fork.js', [], {});
// my_fork.ts
process.send({command: 42});  // Error: Cannot invoke an object which is possibly 'undefined'.
(<Required<typeof process>>process).send({command: 42}); // fine, but ugly

So how can I tell TypeScript that inside my_fork.ts the process.send will never be undefined?

0

There are 0 best solutions below