TypeScript Version: 4.1.2
Search Terms: require.main module
When using Node.js's recommended approach to check if a module is the main module, tsc chokes on the types it infers:
Code
Note: This is JavaScript!
if (require.main === module) { // ERROR TS2367 The types "Module | undefined" and "{ "\"c:/Repositories/ioBroker.test/repro\"": number; }" have no overlap
module.exports = 1; // ERROR TS2339 The property exports does not exist on type `never`
}
Expected behavior:
no error
Actual behavior:
bunch of incorrect errors (see code). I'm not even sure what that type which is inferred for module is supposed to mean.
Playground Link: doesn't work on the playground
Related Issues: #30088