Changing from typescript 3 to 4, what is purpose of new export.somename = void 0 in JS output and new (0,module_1.function)?

I switched from typescript 3 to 4 and there are some odd-looking changes in the output I'd like to understand. The top of most JS output files has new inserted exports.name = void 0 code:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blah = exports.blah2 = void 0;
var something_1 = require(".something");

Later in the file right after the blah() function definition, there is still exports.blah = blah; My best guess is this some strategy to force the exports to null while other modules are loaded and resolved to crash on module startup dependencies.

Another change is calls to other modules are now being transpiled to (0,module_1.function)(....) which was previously just module_1.function(....) and worked fine. I am wondering if the new JS will run fine in old computers or why the old code appeared fine.


The "setting to void 0" (undefined) is because a modules exported names have to be visible even if their initializer hasn't run yet (they are hoisted, like var declarations).

When this makes a difference when there are circular imports, for example:

import * as self from './modulename'  // Where this file is "modulename.ts"
export const v = 'a' in self  // Should be "true"
export const a = 0

And the reason for (0, module_1.function)(args) instead of just module1.function(args) is because this is meant to be undefined when the function is called, and the second one would call the function with this as module1.

This will only break old code that was relying on "this" to be the module. But that code was already broken since that shouldn't have worked in the first place.