weixin_39826080 2020-11-22 01:35
浏览 0

Can't emit types into same namespace as values

 js
interface Foo { x: number; }
var Foo;

is legal TS. But if you translate the interface into Closure directly it goes into the single (value) namespace and the two definitions conflict.

It's easy enough to just emit interfaces under some mangled name in Closure, e.g.

 js
interface Foo { x: number }
/**  */
function tsickle_Foo() {}
/**  {number}
tsickle_Foo.prototype.x;

but then you need to fix every reference to that interface in any Closure type, while at the same time leaving other references (e.g. Array) alone. And you need to figure out how to import it across files (if a file does import {Foo} from bar, you'd need to change it to import {Foo, tsickle_Foo} from bar).

该提问来源于开源项目:angular/tsickle

  • 写回答

7条回答 默认 最新

  • weixin_39826080 2020-11-22 01:35
    关注

    Rado suggested we might be able to do some trickery like

     js
    interface ts_Foo { ... }
    type Foo = ts_Foo;
    

    and then when Foo is used, note that there's an alias and inspect that to get data about the emitted type.

    But a local experiment found that the place where we emit types gets the type after aliasing has been resolved.

    评论

报告相同问题?