🔎 Search Terms
__importStar
module object
namespace object
🕗 Version & Regression Information
- Version: 6.0.2
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "namespace import". I did not found any information related to this.
⏯ Playground Link
https://www.typescriptlang.org/play/?target=99&jsx=0&module=1&ts=6.0.2#code/DYUwLgBADgjBC8ECWBbKB7ATmAFAIgDMBnPASgG4BYAKFEigCYFk0tdCSKaaAFTdFEiIgAdAENgwHAG1YAGmgMAuqRFgAFiAB2OGcRgLiy0ggB8EAN40INiAGN0WoulAjg6AOY59CeIiMUEAD0QRBgmACuIDQAvlzUQA
💻 Code
let p1 = import("fs");
let p2 = import("fs");
Promise.all([p1, p2]).then(([fs1, fs2]) => {
console.log(fs1 === fs2); // expected true
});
🙁 Actual behavior
When the compiled code with node is run, false is printed. This means that the two imported module namespace object is different. each __importStar call create a new module namespace object.
🙂 Expected behavior
true should be printed. The module namespace objects of these two import("fs") should be the same object.
If we run this script directly by node without compiled, true will be printed.
Additional information about the issue
To reproduce this issue, "module" in "tsconfig.json" need to be set to "commonjs". This makes tsc use __importStar and require to import the module.
🔎 Search Terms
__importStarmodule objectnamespace object🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?target=99&jsx=0&module=1&ts=6.0.2#code/DYUwLgBADgjBC8ECWBbKB7ATmAFAIgDMBnPASgG4BYAKFEigCYFk0tdCSKaaAFTdFEiIgAdAENgwHAG1YAGmgMAuqRFgAFiAB2OGcRgLiy0ggB8EAN40INiAGN0WoulAjg6AOY59CeIiMUEAD0QRBgmACuIDQAvlzUQA
💻 Code
🙁 Actual behavior
When the compiled code with node is run,
falseis printed. This means that the two imported module namespace object is different. each__importStarcall create a new module namespace object.🙂 Expected behavior
trueshould be printed. The module namespace objects of these twoimport("fs")should be the same object.If we run this script directly by
nodewithout compiled,truewill be printed.Additional information about the issue
To reproduce this issue, "module" in "tsconfig.json" need to be set to "commonjs". This makes
tscuse__importStarandrequireto import the module.