Typescript - Type Cast (Coercion)

About

Data Type - Coercion (ie Type Conversion) in Typescript

Type

Typescript Assertion

level: loglevel.LogLevelDesc = <loglevel.LogLevelDesc> level

See Typescript - Type Assertion (angle-bracket or as)

Jsdoc

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

/**
 * @type {number | string}
 */
var numberOrString = Math.random() < 0.5 ? "hello" : 100;
var typeAssertedNumber = /** @type {number} */ (numberOrString)

Doc / Ref





Discover More
Javascript - Typescript

TypeScript is a typed superset of JavaScript that compile to plain JavaScript. It adds static typing. JSdocReference See When...
Typescript - Type Assertion (angle-bracket or as)

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



Share this page:
Follow us:
Task Runner