-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
TypeScript declared namespaces break when imports are used #13000
Comments
No, Deno is working correctly... When you have a type definition and you import or export from it, it becomes a module instead of an ambient declaration. Therefore the namespace is scoped to the module and any declaration are scoped to the module. You would need to either export and import the namespace, or declare the namespace globally: declare global {
namespace Namespace {
export type A = boolean;
}
} |
Thanks @kitsonk for your comment, trying to get this working is a nightmare of footguns. Nothing is intuitive about how any of this works. Because all the tooling is so buggy, when something doesn't work it's hard to tell if it's because you're doing something wrong and should reevaluate the approach or if it's just broken. There's no clear examples for the ideal way to work with JSDoc types both as a package publisher and consumer. At this point, it seems global namespaces "imported" via triple slash references is the only way to work since there is no way to declare types when importing within a JSDoc type. Perhaps the solution is to use JSDoc inline A problem is, which triple slash reference is the right one to use? Deno lint has been wrong about triple slash references before, so I don't know if the warning can be trusted. But isn't Another problem is, even if you know the right way to structure this from the consumer side, how do you compose the So even if we know the right way to structure all this both from the publisher and consumer side, how can a consumer work with third party Please help wake me from this nightmare. |
A TypeScript declared namespace incorrectly becomes missing when attempting to consume the
.d.ts
file when the definition file also contains imports.In this example, Deno incorrectly thinks the namespace
Namespace
is missing:If you comment out the import, the namespace is no longer missing:
The text was updated successfully, but these errors were encountered: