Feature Request: Support resolved mapped types #888
Description
Mapped types themselves are fundamentally incompatible with Closure Compiler.
However, the results of mapped types (once all type parameters have been specified) are normal object types that can work fine.
Currently, mapped types are always emitted as ?
.
This FR is to emit any mapped type whose properties are known to Tsickle (IOW, if the in
clause is a resolved type, not a type parameter) as a record literal type ({foo: !Type, ...}
).
This gets interesting with named mapped types (type Foo = { [name in ...]: .... }
); where possible, we should reference the name for brevity / clarity / (for classes or interfaces) to avoid property invalidations.
There are (in general) three categories of type references:
- Anonymous types (a
{}
, not hidden behind an alias)- These can only be emitted as a record literal, or
?
if not expressible
- These can only be emitted as a record literal, or
- Named types whose definitions are expressible (they don't involve keys or intersections from a type parameter).
- These should be emitted as a reference to the name.
- Named types whose definitions are not expressible
- These should be emitted as a record literal (if possible).
Note that these guidelines apply to all type features that are not supported by JSCompiler but can produce object types; this also includes intersection types (#886) & conditional types.
Note that computing whether a type is expressible is a recursive operation that depends on the type parameters passed (examples coming tomorrow).