Languages
[Edit]
EN

TypeScript - variable casting

11 points
Created by:
Kate_C
19800

In TypeScript it is possible to make type casting in following ways.

1. as keyword example

let object : any = 'This is my text...';
let text : string = object as string;

console.log(`'${text}' has ${text.length} characters`);

Output:

'This is my text...' has 18 characters

2. <> brackets example

let object : any = 'This is my text...';
let text : string = <string>object;

console.log(`'${text}' has ${text.length} characters`);

Output:

'This is my text...' has 18 characters

 

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join