Object properties can be type-narrowed by conditionals, but reassigning the whole object to another variable causes an error. Is there any workaround?
type A = {
prop: string | number;
}
type B = {
prop: string;
}
function f(a: A) {
if (typeof a.prop === 'string') {
let str: string = a.prop; // No error
let b: B = a; // Error
}
}