-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esModuleInterop should work even when compiling to esnext modules #22851
Comments
The question is really about what exactly to emit. When you want to emit to ES modules, a default import really needs to continue being a default import. So On the other hand, when you expect an external tool (e.g. Babel, Webpack, SystemJS) to stitch the ES interop on its own, that's when you can use I guess you could make the argument that |
The problem with |
@DanielRosenwasser Doesn't it already? From Emit __importStar and __importDefault helpers for runtime babel ecosystem compatibility and enable --allowSyntheticDefaultImportsfor typesystem compatibility. |
|
Do note that Node 12.x only supports the import legacy from "cjs-package"; This doesn’t work: import { method } from "cjs-package"; The only exception to that are built‑in modules, which have special handling. |
This issue seems to have been resolved in TypeScript |
Hi, Just checking is this issue has been resolved? I am facing a similar as was raised by @jamiebuilds here I am using a library that is exporting a function as Project sandbox can be found here. TS Project setup as commonjs
TS Project setup as esm
I have tried with Any workaround or suggestion will be very much appreciated. |
@bhvngt Your problem is different from this issue. It is the current TypeScript specification. |
Thanks @teppeis. Got it. Will raise this issue in |
TypeScript Version: 2.7.2
Search Terms: esModuleInterop, esnext, modules, import, export, default
Code
With this type definition:
Running with:
Produces these errors when importing:
But, if you use commonjs modules:
It works as expected (because of
--esModuleInterop
)Expected behavior:
It is understandable that the type checker doesn't want to pretend the import is interop'd when it's not compiling in the helpers.
But if you've specified
--esModuleInterop
and--module esnext
the assumption from the type checker should be that an external system is applying the interop. Otherwise why would you specify--esModuleInterop
?Playground Link: https://github.com/jamiebuilds/ts-bug
The text was updated successfully, but these errors were encountered: