变量有可能充当类型保护吗?
type Union = string | {prop: string};
function test(u: Union) {
if (typeof u === "string") {
u;
// ^? (parameter) u: string
}
if (typeof u === "object") {
u;
// ^?(parameter) u: { prop: string }
}
let check = typeof u === "object";
// ^?let check: boolean
if (check) {
u.prop;
// ^?(parameter) u: Union
}
}