-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Imports left out of module dependencies when not directly assigned or assigned to. #2132
Comments
@danquirk It's an arbitrary and dangerous thing to have the TypeScript engine take on the responsibility of optimizing the import statements. There are many patterns that TypeScript does not yet capture from JavaScript. One example is how it does not address that Import is used to load dependencies before the current code is loaded and may not be referenced directly. Angular dependencies are one example, while jQuery plugins are another. Any library that extends a base object and is not referenced directly are affected by "feature". By deciding to arbitrarly not included an import based on local static analysis you are imposing a C style compiler pattern over the explicit intention of the developer who wrote the import statement. The expectation of writing import is that it will be included as a dependency and available to the local scope of the module. Any other action is a side effect to the natural expectation of choosing to write It is very possible that in this case the TypeScript compiler could do less, and accomplish more. |
The problem is an imported module may only contain ambient declarations, in which case leaving the import behind could result in a runtime error, because the file itself may not exist at runtime. See #596 (comment) This does preclude certain patterns, for example CommonJS extensions. But that may be the lesser of the two evils. (BTW copying the same comment across issues is rather bad form.) |
To your comment ambient declarations are addressed by (Hey @NoelAbrahams, I gave unique comments, articulated specifically for each thread. It doesn't change that |
In the following case a module defined in TypeScript will not be included in the required modules of the module.
The module that is generated is:
Instead of:
Assigning
something
to another value or accessing the properties ofsomething
will cause it to be added to the module signature.In any case the values defined in the
import x = require('y')
should be added to the module dependencies. The author has explicitly added the reference and as such has an expectation that it will be included in the dependencies of the current module.The text was updated successfully, but these errors were encountered: