This is a bit like type casting , since it does not come with runtime support (only its compilation time statement) TypeScript allows you to call it โStatement Typeโ. Consider this example:
var element1 = document.getElementById('canvas'); // Determined to be HTMLElement element1.getContext('2d'); // ERROR as it is HTMLElement // Determined to be canvas due to your assertion var element2 = <HTMLCanvasElement>document.getElementById('canvas'); element2.getContext('2d'); // Valid
You will need it whenever the output of TypeScript type leads to the fact that you cannot assign things due to incompatible supposed types.
source share