Type Assertions
as tells the compiler to treat a value as a type. It does not convert the value, so use it carefully.
Example
const v: unknown = "hello";
const len = (v as string).length;
console.log(len);Result
5
Exercise
Assert a type.
(v string)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.