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
Actual behavior:
Assignment fails because the result type of makeTestObj is {'test': string} rather than {'test': 'a' | 'b' }.
I vaguely recall that the rules for widening depend on whether a value is mutable, so my guess is that the widening is happening on the property's type because properties are mutable. Still, would it make sense not to widen here? Or maybe the current behavior is good, since it forces me declare explicitly that makeTestObj returns an AorBValuedObj?
The text was updated successfully, but these errors were encountered:
This is working as intended. In makeTestObj you need some indication that you don't want the test property widened (e.g. a return type annotation or a type assertion on the returned value). Absent that, the compiler widens the type because a property is a mutable location.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.4.1
Code
Expected behavior:
Assignment to
x2
succeeds.Actual behavior:
Assignment fails because the result type of
makeTestObj
is{'test': string}
rather than{'test': 'a' | 'b' }
.I vaguely recall that the rules for widening depend on whether a value is mutable, so my guess is that the widening is happening on the property's type because properties are mutable. Still, would it make sense not to widen here? Or maybe the current behavior is good, since it forces me declare explicitly that
makeTestObj
returns anAorBValuedObj
?The text was updated successfully, but these errors were encountered: