TypeScript Version: 4.0.2
Search Terms:
tslib, __importDefault
Code
Using "noEmitHelpers": true and "importHelpers": true does not always include tslib_1 in files, in the last example __importDefault is in the index.js file, without any tslib_1
tsconfig
{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"lib": [
"es2017", "dom", "es2018.promise"
],
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "./src",
"declaration": true,
"noLib": false,
"outDir": "target/lib/ts",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"strictBindCallApply": false,
"esModuleInterop": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"noEmitHelpers": true,
"importHelpers": true
},
"exclude": [
"node_modules",
"target"
]
}
TypeScript 3.9.7
// index.ts
export * from "./core/Core";
export {default as HandlerManager} from "./core/HandlerManager";
// becomes
// index.js
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./core/Core"), exports);
var HandlerManager_1 = require("./core/HandlerManager");
Object.defineProperty(exports, "HandlerManager", { enumerable: true, get: function () { return HandlerManager_1.default; } });
Here tslib_1 is only used for exportStar and HandlerManager is not wrapped in __importDefault
TypeScript 4.0.2
// index.ts
export * from "./core/Core";
export {default as HandlerManager} from "./core/HandlerManager";
// becomes
// index.js
Object.defineProperty(exports, "__esModule", { value: true });
// lots of exports, removed because only HandlerManager is relevant
exports.firstExport = ... = exports.HandlerManager = void 0;
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./core/Core"), exports);
var HandlerManager_1 = require("./core/HandlerManager");
Object.defineProperty(exports, "HandlerManager", { enumerable: true, get: function () { return tslib_1.__importDefault(HandlerManager_1).default; } });
Here HandlerManager is imported correct with tslib_1, however if we remove the * import from index.ts, we have
// index.ts
// export * from "./core/Core";
export {default as HandlerManager} from "./core/HandlerManager";
// becomes
// index.js
Object.defineProperty(exports, "__esModule", { value: true });
// lots of exports, removed because only HandlerManager is relevant
exports.firstExport = ... = exports.HandlerManager = void 0;
// export * from "./core/Core";
var HandlerManager_1 = require("./core/HandlerManager");
Object.defineProperty(exports, "HandlerManager", { enumerable: true, get: function () { return __importDefault(HandlerManager_1).default; } });
Now we have __importDefault , but tslib is not imported and __importDefault doesn't come from tslib, so __importDefault is undefined
Expected behavior:
tslib should be imported in index.js and importDefault should be called like tslib_1.__importDefault
Actual behavior:
__importDefault without any tslib in index.js
Playground Link: Not possible, requires more than 1 file
Related Issues: No similar issues
TypeScript Version: 4.0.2
Search Terms:
tslib, __importDefault
Code
Using
"noEmitHelpers": trueand"importHelpers": truedoes not always includetslib_1in files, in the last example__importDefaultis in the index.js file, without anytslib_1tsconfig
{ "compileOnSave": false, "compilerOptions": { "target": "es5", "lib": [ "es2017", "dom", "es2018.promise" ], "module": "commonjs", "moduleResolution": "node", "rootDir": "./src", "declaration": true, "noLib": false, "outDir": "target/lib/ts", "allowSyntheticDefaultImports": true, "sourceMap": true, "strictBindCallApply": false, "esModuleInterop": true, "strictNullChecks": true, "noUnusedLocals": true, "noImplicitAny": true, "noEmitHelpers": true, "importHelpers": true }, "exclude": [ "node_modules", "target" ] }TypeScript 3.9.7
Here
tslib_1is only used forexportStarandHandlerManageris not wrapped in__importDefaultTypeScript 4.0.2
Here
HandlerManageris imported correct withtslib_1, however if we remove the*import from index.ts, we haveNow we have
__importDefault, buttslibis not imported and__importDefaultdoesn't come fromtslib, so__importDefaultisundefinedExpected behavior:
tslibshould be imported in index.js andimportDefaultshould be called liketslib_1.__importDefaultActual behavior:
__importDefaultwithout anytslibin index.jsPlayground Link: Not possible, requires more than 1 file
Related Issues: No similar issues