UnaryExpression: ( Modified ) … Type >
UnaryExpression
In a type assertion expression of the form < T > e, e is contextually typed (section ) by T and the resulting type of e is required to be assignable to T, or T is required to be assignable to the widened form of the resulting type of e, or otherwise a compile-time error occurs. The type of the result is T.
the type annotations indicate that the ‘createShape’ function might return a ‘Circle’ (because ‘Circle’ is a subtype of ‘Shape’), but isn’t known to do so (because its return type is ‘Shape’). Therefore, a type assertion is needed to treat the result as a ‘Circle’.
var shape = createShape(shapeKind);
var circle = <Circle> shape;
}
TODO: Document as operator.