-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Statements aren't inlined if they are used in declare global
statements only
#214
Comments
Minimal repo showing the issue: https://github.com/ext/dts-bundle-generator-issue-214 |
… used in a declare global statement See #214
Hi @ext, Thanks for reporting this. It looks like the tool doesn't take into consideration for "whether a type is exported" global types that you're going to include into a bundle. The bug is that the tool works in the way that it gets the list of export statements from an entry point and uses it as a "basis" to check "whether a statement is exported or is used any any root export indirectly via any chain is usages". Obviously global declaration statements aren't part of this check and that's why It might be tricky though to get it fixed, because afaik there is no compiler API to get all "global" statements (or especially all global statements that we declared in the program). We can try to collect these statements manually, but we need to keep in mind that For these of you who reads this and who would like to take a took into the issue, debug it or provide a fix, I created a branch with adding a test case (created by @ext - thank you for that!) - https://github.com/timocov/dts-bundle-generator/tree/issue214. |
declare global
statements only
…declare global` statements Fixes #214
Released in v8.0.0. |
Awesome, thank you very much for implementing this! ❤️ |
Bug report
Declared global namespaces is stripped or does not contain the necessary imports.
Not sure if I just cant get the options right of if there is something else wrong.
Input code
(The contents on
FooOptions
is irrelevant, even an empty interfaceexport interface FooOptions {}
causes the problem)Expected output
Above code intact in the output file.
Actual output
dts-bundle-generator src/foo.ts -o dist/foo.d.ts
Without any flags I get an empty export:
dts-bundle-generator --inline-declare-global src/foo.ts -o dist/foo.d.ts
With
--inline-declare-global
I get the global namespace in the output file but without theFooOptions
import:This is also detected when
dts-bundle-generator
checks the result:Additional context
Manually inlining the types in the same file works as expected but is not really viable in a real world scenario (more complex types being shared between multiple files)
For context, this happens when I'm trying to use
dts-bundle-generator
on a Cypress plugin using the technique highlighted in their documentation: Types for Custom Commands:commands.ts
Thanks for writing and maintaining this tool, I find it really useful and easier to use than alternatives.
The text was updated successfully, but these errors were encountered: