Make import fix for 'export =' respect module target and allowSyntheticDefaultImports/esModuleInterop#32150
Make import fix for 'export =' respect module target and allowSyntheticDefaultImports/esModuleInterop#32150andrewbranch wants to merge 5 commits intomicrosoft:masterfrom
Conversation
5989910 to
2714043
Compare
Way back when |
|
@weswigham but namespace imports of callable things are still allowed even without |
Precisely. It's only with the |
|
Ah, got it. So I think the question remains: given an |
If there's an |
@RyanCavanaugh That’s the current behavior—but the issue (#31219) is that I suppose for <es2015 it’s debatable—I can undo my changes for those cases. |
|
This PR now only changes the behavior when esModuleInterop/allowSyntheticDefaultImports is on—it prefers the default import in that case. |
|
Fixes #29038 |
|
This PR now only changes the behavior when esModuleInterop/allowSyntheticDefaultImports is enabled and |
|
The conversation around this PR has just gotten too confusing—I initially didn’t realize that |

Fixes #31219
The change here is super simple. For an export assignment (
export = foo):import foo from "foo"else if your module target is ES2015+, preferimport * as foo from "foo". (This is invalid, but so is literally anything else with this combination of export form and compiler options, and this one gives the best error message.)import foo = require("foo")(what previously happened for all cases)It is possible to use
import * as foo from "foo"for some additional cases, but I wanted to get clarified feedback on exactly which cases. My understanding is that, assumingallowSyntheticDefaultImport/esModuleInteropis disabled, export assignments roughly fall into three logical categories:import foo = require("foo"): includes classes, interfaces, types, enums. (From reading old docs, it sounds like this used to be the only category—export =mandatedimport foo =, bar none.)import * as foo from "foo"within ES module spec compliance: includes values that are not callable/constructable.import * as foo from "foo"but apparently violates ES module spec: values that are callable/constructable. (E.g.import * as express from "express"; express()works today, but I think it didn’t at some point in the past, because it‘s technically wrong?)There’s a lot of history here that’s not particularly well-documented as far as I can find—calling on @DanielRosenwasser to help unearth the archives and advise.