-
Notifications
You must be signed in to change notification settings - Fork 109
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
Invalid code generated with 'export module' declaration #713
Comments
Within Google we disallow use of namespaces ('module' is an obsolete alias for the 'namespace' keyword here I think), in part because they generate code that confuses Closure compiler. I think in particular if you start nesting |
@evmar Interesting. Is there a public collection of this kind of thing that confuses the compiler? I'm currently migrating a pretty large (500K LOC) codebase to a Typescript/Closure Compiler stack and it'd be great to know about this kind of stuff. Does this tslint.json cover it? Our existing codebase declares a lot of properties on functions, and my translation is using declaration merging with namespaces to accomplish this. I assume you use an interface for this instead? |
We don't have it well-documented unfortunately. The actual line is always kinda vague and varies with the rules of Closure compiler. Coincidentally, just today I learned about properties on functions in Closure syntax. Search for "hacky" on http://closuretools.blogspot.com/2017/01/common-pitfalls-when-using-typedefs-in.html . Since I only learned about this today I doubt tsickle does the right thing here, but it might accidentally work. |
(Note that by default tsickle leaves types out everywhere, as it's more concerned with "get the compiler to accept this code" than it is about "properly express these types so that the compiler understands them". So it often is the case that things accidentally work.) |
Doing it using declaration merging actually does look like it works! No type comments are generated for those expressions and so the compiler accepts it. |
Minimal reproduction follows:
test.ts
Output: test.js
Compiling with Closure Compiler v20180101 (the latest at the time of this writing) fails with this error:
As a workaround, doing the export on a separate line generates working code:
The text was updated successfully, but these errors were encountered: