-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
P3buginternal-issue-createdAn internal Google issue has been created to track this GitHub issueAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.Has been reviewed by someone on triage rotation.
Metadata
Metadata
Assignees
Labels
P3buginternal-issue-createdAn internal Google issue has been created to track this GitHub issueAn internal Google issue has been created to track this GitHub issuetriage-doneHas been reviewed by someone on triage rotation.Has been reviewed by someone on triage rotation.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
brad4d commentedon Oct 30, 2018
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 literalpassed to
f
has ay
property containing a string. The transpilation of object rest probably obscuresthis. 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 commentedon Dec 29, 2018
FYI: TypeScript supports it (sample code)
brad4d commentedon Jan 2, 2019
Internal issue created http://b/122266991
brad4d commentedon Apr 9, 2019
@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.