You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Object spread allows unknown properties as function return values #17422
It seems that spread completely disables excess property checking, and that that was an intentional decision.
Though I'm not sure what would be the harm in checking for excess properties for the non-spread (directly specified) keys, especially when there is a contextual type 😕
where the explicit return type annotation on the value that implements fun is what triggers the error.
FWIW, I think the current behavior is just fine. Anything more rigid would wreck many simple and practical factory patterns and make perfectly reasonable and sound assignability relationships illegal.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
compiling just fine.
I was gonna write code a lot like the second example (for redux reducers) but it won't properly typecheck like that so I would have to introduce intermediary variables which will appear in the output as well which I'd rather avoid.
Activity
Jessidhia commentedon Jul 26, 2017
It seems that spread completely disables excess property checking, and that that was an intentional decision.
Though I'm not sure what would be the harm in checking for excess properties for the non-spread (directly specified) keys, especially when there is a contextual type 😕
thasner commentedon Jul 26, 2017
@Kovensky that's not true.
On TS 2.4.2 this code sample emits the appropriate error:
aluanhaddad commentedon Jul 27, 2017
Thomas Hasner (@thasner) your example is actually not the same as that in the OP though.
The OP example is
such that the excess property,
bar, is accepted as part of the inferred return type of the function variable's valueIn your example
an intermediate, explicitly typed variable is introduced and that is where the error is triggered.
It is as if you had written
where the explicit return type annotation on the value that implements
funis what triggers the error.FWIW, I think the current behavior is just fine. Anything more rigid would wreck many simple and practical factory patterns and make perfectly reasonable and sound assignability relationships illegal.
mhegazy commentedon Sep 6, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
olee commentedon May 30, 2018
I would like to ask why this was closed.
The example presented above shows how weird this behaves with
correctly throwing an error, but
compiling just fine.
I was gonna write code a lot like the second example (for redux reducers) but it won't properly typecheck like that so I would have to introduce intermediary variables which will appear in the output as well which I'd rather avoid.
RyanCavanaugh commentedon May 31, 2018
Björn Zeutzheim (@olee) see #12632