Table of Contents

Typescript - Type Assertion (angle-bracket or as)

About

Type assertions gives type information to typescript generally to details the type information of an any variable type.

It does not perform any special check or restructuration of data such as a type cast.

Syntax

angle-bracket

The “angle-bracket” syntax:

let someValue: any = "this is a string";
let strLength: number = (<string>someValue).length;

as-syntax

let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;

Documentation / Reference