Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

Feature Request: Support resolved mapped types #888

Open
@SLaks

Description

@SLaks

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:

  1. Anonymous types (a {}, not hidden behind an alias)
    • These can only be emitted as a record literal, or ? if not expressible
  2. 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.
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions