Reject Circular References between Namespaces #270
Labels
closed-for-staleness
effort/large
Large work item – several weeks of effort
feature-request
A feature should be added or improved.
p2
It appears (correct me if I'm wrong), that because namespaces in TypeScript are objects not actual modules, that something like:
is possible to do?
Currently the Python code is structuring namespaces as individual modules because it does not have a "namespace" concept that is distinct from it's module system. This combined with code like the above, means that the Python code cannot generate workable code, because the top level module (say
widget
) would import from the submodule (widget.bar
), and the sub module would then import from the top level module (widget
).At a minimum the JSII compiler should probably try to detect cycles like these, and reject them.
It might be worthwhile to consider being even stricter. It's generally, in my opinion, good form to have modules/namespaces like this not depend on something "higher" up in the tree (while depending on stuff "lower" in the tree is fine). That would generally mean (in my example above) that the module root could use anything from the bar namespace, but the bar namespace could not use anything from the module root.
This would likely entail needing to add some construct in the JSII to signal the need to re-export a type from one namespace to another namespace, because it appears the primary place we're violating this hypothetical rule, is when we want to share an attribute type between two different modules. It might be saner to implement that as a type defined in the "inner" namespace, and then explicitly re-exported from that namespace into the "outer" namespace.
The text was updated successfully, but these errors were encountered: