Typescript - Type Assertion (angle-bracket or as)

1 - 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.

2 - Syntax

2.1 - angle-bracket

The “angle-bracket” syntax:


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

2.2 - as-syntax


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

3 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap