You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ES Module imports discarded when they include a type and a side-effect #28285
Wesley Wigham (@weswigham) Certainly looks like it, only this is explicit ESNext modules and #9191 is referencing require - I assume that means a fix for require would be a fix for ESNext modules?
Only require is doing some mapping and ES Modules aren't - I think there's potentially a much easier fix for this as for ESNext modules in TS you have to include the .js suffix, so:
import { MyComponent } from './my-component'; // gets definition from my-component.d.ts
import { OtherComponent } from './other-component.js'; // doesn't need to check, always include in JS output
#9191 has been sitting round for years without a fix because finding out whether the reference includes a side effect is incredibly difficult.
However this could be fixed by adding a special case for ESNext when an explicit .js file extension is present.
As a fix for this wouldn't necessarily be a fix for #9191 does this still count as a duplicate? Especially as #9191 is never going to get fixed (require will get deprecated first) and ES Modules will become the standard?
Even if the import includes .js extension, we still look up an associated .d.ts file, and you might still only use the types from it. The presence of an extension doesn't change anything, really.
Wesley Wigham (@weswigham) yes, so for TS the extension is optional, but for JS missing the extension will throw an error. The only reason to include the extension in TS is because you want the import to work in the JS output, and in that case you always want to retain it.
Imports with explicit .js extensions should always be in the output.
Activity
weswigham commentedon Nov 1, 2018
Duplicate of #9191 I imagine.
KeithHenry commentedon Nov 1, 2018
Wesley Wigham (@weswigham) Certainly looks like it, only this is explicit ESNext modules and #9191 is referencing
require- I assume that means a fix forrequirewould be a fix for ESNext modules?Only
requireis doing some mapping and ES Modules aren't - I think there's potentially a much easier fix for this as for ESNext modules in TS you have to include the.jssuffix, so:#9191 has been sitting round for years without a fix because finding out whether the reference includes a side effect is incredibly difficult.
However this could be fixed by adding a special case for ESNext when an explicit
.jsfile extension is present.As a fix for this wouldn't necessarily be a fix for #9191 does this still count as a duplicate? Especially as #9191 is never going to get fixed (
requirewill get deprecated first) and ES Modules will become the standard?weswigham commentedon Nov 1, 2018
Even if the import includes
.jsextension, we still look up an associated.d.tsfile, and you might still only use the types from it. The presence of an extension doesn't change anything, really.KeithHenry commentedon Nov 3, 2018
Wesley Wigham (@weswigham) yes, so for TS the extension is optional, but for JS missing the extension will throw an error. The only reason to include the extension in TS is because you want the
importto work in the JS output, and in that case you always want to retain it.Imports with explicit
.jsextensions should always be in the output.