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
Contextual typing not working on optional members #16817
The following sample works perfectly in noImplicitAnyunless I turn on strictNullChecks. In that event, the s parameter on foo seems to get an implicit any.
This isn't strictNullChecks specific (though it's much easier to trigger the bug there); we're failing to produce parameter inferences for any parameter within an index within a union:
This is working as intended. The actions property of the object literal is contextually typed by a type parameter type Actions, and during the inference process we don't yet know what the type argument for Actions will be (and constraints don't factor into type inference). I suggest rewriting the example to:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
This issue is tagged incorrectly and we have a fix up, it's pretty simple. We actually do contextually type the nonunion case right (the generic's constraint is the contextual type), so it is, in fact, a bug that a union is not appropriately contextually typed. The issue is that when we get the apparent type of a contextual type, we didn't get the apparent type of all union members - we just returned the union.
Activity
weswigham commentedon Aug 7, 2017
This isn't
strictNullChecksspecific (though it's much easier to trigger the bug there); we're failing to produce parameter inferences for any parameter within an index within a union:ahejlsberg commentedon Oct 20, 2017
This is working as intended. The
actionsproperty of the object literal is contextually typed by a type parameter typeActions, and during the inference process we don't yet know what the type argument forActionswill be (and constraints don't factor into type inference). I suggest rewriting the example to:If it is really important to capture the actual type of the object literal, it can be done with an intersection type:
(I omitted the
viewproperty to reduce noise.)mhegazy commentedon Nov 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.
weswigham commentedon Nov 6, 2017
This issue is tagged incorrectly and we have a fix up, it's pretty simple. We actually do contextually type the nonunion case right (the generic's constraint is the contextual type), so it is, in fact, a bug that a union is not appropriately contextually typed. The issue is that when we get the apparent type of a contextual type, we didn't get the apparent type of all union members - we just returned the union.