It helps to correctly import a default export in CommonJS/AMD/UMD module format.
A default import (i.e. import d from “foo”) for a CommonJS/AMD/UMD module is equivalent to
const d = require("foo").default
But most of the CommonJS/AMD/UMD modules available today do not have a default export, making this import pattern practically unusable to import non-ES modules
(i.e. CommonJS/AMD/UMD).
For instance
import fs from "fs"
or
import express from "express"
are not allowed.
To allow default imports in CommonJS/AMD/UMD (e.g. import fs from “fs”), the typescript compiler adds __esModule flag and checks it in a transpiled code (from ES6 to CommonJS). It imports default exports by using an __importDefault helper function (which checks the __esModule flag).
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
exports.__esModule = true;
var bar_1 = __importDefault(require("bar"));