Type Assertions is the process of manually specifying data types. There are two formats.
as
<data type>
Example 1: Using the as
format.
let data1:unknown;
data1="Apple";
let fruit = (data1 as string).toLowerCase();
console.log(fruit);
Example 2: Using the <data type>
format.
let data1:unknown;
data1="Apple";
let fruit = (<string>data1).toLowerCase();
console.log(fruit);
Top comments (0)