-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Import named default
is typed differently than default import (with moduleResolution: node16)
#49567
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
Comments
Hm, I'm guessing we're missing the logic we use for resolving default imports on named-imports-named-default. Should probably unify those codepaths. |
I have some more information - it seems related: If
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.def = void 0;
function def() { }
exports.def = def;
exports.default = def; import mod2, {default as def} from 'foo' In node: In TS:
If
export function def() {}
export default def import mod2, {default as def} from 'foo' In node: In TS:
It seems like TS needs to read the |
Oh, I misread the repro initially -
is a questionable configuration. You probably wanna set |
@weswigham In the repro repo I switched |
Ah, you're right, my initial assessment was right; I was just thrown off by the incorrect compiler option. It's probably worth noting that this divergent behavior between the two kinds of default imports checking-wise can also be observed in older emit modes just using |
Was this issue actually fixed in v4.8.3? changing typescript version to |
Bug Report
🔎 Search Terms
default import, default export, named default export, module resolution, node 16
🕗 Version & Regression Information
Version 4.7.3
I also tried nightly, it is present there too.
⏯ Playground Link
Can't use playground because it requires multiple files.
https://github.com/calebeby/ts-import-bug
💻 Code
In node,
mod2
anddef
are the "CJS namespace import" as described in the Node docs.foo.d.ts:
If I switch
moduleResolution
tonode
,mod2
anddef
have the same type (not matching node's native ESM behavior, but that is expected sincemoduleResolution
is not set tonode16
)🙁 Actual behavior
🙂 Expected behavior
def
andmod2
should have the same type (the CJS namespace). TS should say that thedef()
line is an error.def === mod2
should not sayThis condition will always return 'false'
The text was updated successfully, but these errors were encountered: