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





Discover More
Javascript - Dynamic Import (Module, Json)

dynamic import is in stage 4. is when the import statement is used as a function in order to execute it at runtime. The import() function-like form takes the module name as an argument and returns...
Typescript - Type Cast (Coercion)

in Typescript See Typescript borrows cast syntax from Closure. This lets you cast types to other types by adding a @type tag before any parenthesized expression. Doc...



Share this page:
Follow us:
Task Runner