Skip to content

Object spread fails to type check #3132

Activity

brad4d

brad4d commented on Oct 30, 2018

@brad4d
Contributor

It is true that the typecheck passes haven't yet been updated to understand object spread.
Instead object spread is transpiled away before type checking.
I wouldn't expect that to change until sometime next year.

Since o is a constant, one would expect the compiler to be able to figure out that the object literal
passed to f has a y property containing a string. The transpilation of object rest probably obscures
this. It is possible that this issue will be solved "for free" when the transpilation moves after type checking, but I'm not certain of that.

In any case I wouldn't expect us to work at fixing it until the transpilation pass gets moved.

In the meantime the workaround is to use a cast.

teppeis

teppeis commented on Dec 29, 2018

@teppeis
Contributor

FYI: TypeScript supports it (sample code)

brad4d

brad4d commented on Jan 2, 2019

@brad4d
Contributor

Internal issue created http://b/122266991

added
internal-issue-createdAn internal Google issue has been created to track this GitHub issue
on Jan 2, 2019
added
triage-doneHas been reviewed by someone on triage rotation.
on Apr 8, 2019
brad4d

brad4d commented on Apr 9, 2019

@brad4d
Contributor

@teppeis thanks for pointing that out, but we were actually aware of this.

We disagree with TypeScript on this issue because we have different goals.
TypeScript doesn't care about optimizing output code size, but that's one of our primary focuses.

Some of our advanced optimizations rely on the compiler knowing about all places where a given property is read or written and can break code when some of them are hidden.
Type errors like this one help our users recognize that they are writing code that closure-compiler cannot analyze as well and could be problematic to compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3buginternal-issue-createdAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @teppeis@arv@brad4d

        Issue actions

          Object spread fails to type check · Issue #3132 · google/closure-compiler