fix(36909): wrong error message when trying to named-import an export#36925
fix(36909): wrong error message when trying to named-import an export#36925DanielRosenwasser merged 1 commit intomicrosoft:masterfrom
Conversation
andrewbranch
left a comment
There was a problem hiding this comment.
Thanks @a-tarasyuk, that was fast! Code looks good but I want to get @DanielRosenwasser to double check my proposed messages and the conditions for choosing between them. It’s also worth looking at where the similar TS2497 is issued:
This module can only be referenced with ECMAScript imports/exports by turning on the '{0}' flag and referencing its default export.
I noticed that it does some logic to determine whether to report the flag allowSyntheticDefaultImports or esModuleInterop, but I haven’t internalized why. It also may be reasonable to try to come up with a message that doesn’t duplicate that part of TS2497, as I think they’ll always appear together.
|
@andrewbranch Sure, I opened PR to start the discussion. |
|
@a-tarasyuk can you take this out of draft state? |
|
My thinking is to always suggest
Thoughts @weswigham? One thing that I'm not totally sure about whether this error message is "fine" for plain objects and namespaces - we're effectively nudging people to import it as a default, but arguably import * as x from "./x`;is reasonable for most TypeScript users importing from // x.d.ts
declare let x: { foo(): x.Foo }
namespace x {
export interface Foo {
blah: number;
}
}
export = x; |
|
|
|
I need a "laughing but crying" reaction on GitHub 😅😂😭 |
Do you mean that just need to check if the option |
|
@DanielRosenwasser does this need to go into 3.9? If so, can you reply to @a-tarasyuk's question? |
|
For the upcoming release, we can use the message - |
|
This can go into 3.9.1 (RC). @a-tarasyuk I just meant that instead of |
|
My suggestion was to use the same logic as here to populate the option name ( But, I’m not totally sure the module target is actually a good heuristic, given that Webpack and other bundlers are going to do their own thing with modules—in other words, saying your module target is es2015+ doesn’t necessarily mean you’re ultimately going to run with es2015 modules at the end of your pipeline, and you may still need interop. Personally, I’ve never been in a situation where |
|
Thanks for the detailed feedback :). Maybe we can simplify messages something like this What do you @DanielRosenwasser, @andrewbranch think? |
If the module kind is < es2015, these statements aren’t true 😄 because it can be imported using an ImportEqualsDeclaration. Also, I only just now noticed the existing message I screenshot (emphasis mine):
Declared with using?! Either “with” or ”using” needs to be deleted. What a mess. @a-tarasyuk I think the best approach is just to keep what you have, but replace |
andrewbranch
left a comment
There was a problem hiding this comment.
Thanks for hanging in there; this looks good to me!
|
I think the question is still whether we should ever recommend // bar.ts
import * as foo from "foo";
foo(); // error in esModuleInterop, not in allowSyntheticDefaultImportsIs that accurate @weswigham? |
|
Yeah, that's the difference for that target. |
|
Sure, but none of these error messages recommend a namespace import. They recommend esModuleInterop + a default import. The benefit of esModuleInterop is you can use a default import on a CommonJS export and actually expect it to work at runtime. I’m honestly confused about what So yeah, I don’t really see any reason to recommend |
It was to recognize the behavior of Webpack (and eventually Babel once it could understand TS code) during type-checking. We didn't want to change our own emit, and eventually we recognized that it would be useful.
It's just a better newer version of the flag. |

Fixes #36909