Appearance
src/09-assertion-guards.ts โ
From TS practice (practice/) ยท original: practice/src/09-assertion-guards.ts ยท all files in this project
ts
//type assertions
let someValue:unknown ="subscribe to me";
let strLength:number = (someValue as string).length;
let strLength2:number = (<string>someValue)//. adds access to many methods
//Type guards
let processValue = (value:string|number)=>{
if (typeof value ==="string"){
console.log(value.toUpperCase());
}else{
console.log(value.)
}
}