Рет қаралды 7
Type assertions in TypeScript are a way to tell the compiler explicitly that you know the type of a variable better than it does. They are used when you have more information about the type of a value than TypeScript’s type checker is able to infer. Type assertions do not perform any runtime checks or conversions; they simply inform the compiler of the assumed type.
Angle-bracket syntax:-
let someValue: any = "this is a string";
let strLength: number = (someValue).length;
as syntax:
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;