Instead of using declare namespace to share the types. This allows the generated code to be compiled with closure with full optimizations.
Relates to #9380