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
Description: A type assertion operator that doesn't perform downcasting. This comes up reasonably often and is especially useful when you want to write an expression where the expression's target type is any/unknown but you know what type the expression ought to have.
// We want to validate that the object literal here is a Point3D,// but the downcast here doesn't catch our miss of "z"writeFile("point.json",JSON.stringify({x: 2,y: 5}_as_Point3D);
This is also useful when writing function expressions or objects containing function expressions - its parameters can get contextually typed by the asserted-to type, but you really don't want downcasting of the return types to occur here.
#16605 tracks a different proposal for allowing a downcasting that downcasts the existence of missing properties but does not allow downcasting of types -- this is sort of ill-defined IMHO and needs some justification to exist as a separate entity.
Description: You currently have to choose between index signature validation at the initialization site or getting type checking on property existence:
This is a disambiguator issue for tracking various type assertion-like constructs that have been requested
"is" type assertion
Tracking at #7481
Description: A type assertion operator that doesn't perform downcasting. This comes up reasonably often and is especially useful when you want to write an expression where the expression's target type is
any
/unknown
but you know what type the expression ought to have.This is also useful when writing function expressions or objects containing function expressions - its parameters can get contextually typed by the asserted-to type, but you really don't want downcasting of the return types to occur here.
#16605 tracks a different proposal for allowing a downcasting that downcasts the existence of missing properties but does not allow downcasting of types -- this is sort of ill-defined IMHO and needs some justification to exist as a separate entity.
"pass-through" type assertion
Tracking at #26045
Description: You currently have to choose between index signature validation at the initialization site or getting type checking on property existence:
The idea is some kind of annotation that still allows for inference, but doesn't change the type of the expression
Others
There are more to be found
The text was updated successfully, but these errors were encountered: