-
Notifications
You must be signed in to change notification settings - Fork 12.9k
import statement from "node" in js source file could produce correct declaration path. #41816
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
Conversation
This comment has been minimized.
This comment has been minimized.
export default Foo; | ||
declare class Foo extends EventEmitter { | ||
} | ||
import { EventEmitter } from "events"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so the key point to this test is that this .d.ts
doesn't turn into node/events
because it's a special case global 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix seems incorrect and an odd special case. We expect in cases like this one, to use the module name specified by the ambient module declaration, not one from a filepath. Since the module is declared as declare module "events"
we should only be using "events"
to refer to it, and should never have looked at a filepath to begin with (notably: there's no guarantee the ambient module has the same name as the containing file!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change needs to be reverted and correctly fixed as @weswigham points out correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.... Sorry for the misleading...
And, I am a little confused, if there is not any special folder, according to the module resolution https://www.typescriptlang.org/docs/handbook/module-resolution.html. How could file find the correct modules? Did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auh, I find this https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html#-reference-ing-a-module and finally understand why it is called "ambient" module......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#41895 this one!
Thanks! |
…declaration path. (microsoft#41816) * fix microsoft#41800 * add test * fix test
Fixes #41800