There's an interesting scenario when it comes to assigning a variable of type unknown
to another variable. TypeScript requires us to perform type checking on the unknown
variable, but how does TypeScript handle this specific situation? It appears that TypeScript is looking for a boolean response, but in reality, the solution may be more complex:
let first: unknown = 5;
let second: number;
const result = typeof first === 'number';
if(result){
second = first; // error : Type 'unknown' is not assignable to type 'number'
}
if(typeof first === 'number'){
second = first; // no errors
}