Fill: typeof Guard
填空题 简单
题目
Fill in 空白到 narrow x 到字符串:
代码
function process(x: string | number) {
if (___ x === "string") {
return x.toUpperCase();
}
return String(x);
}
提示
Use typeof 运算符到 检查运行时类型的 值.
解释
运算符是 typeof. typeof x === "字符串" 是构建-in 类型 guard 那个 narrows x 到字符串内部如果块. TypeScript recognizes typeof 检查 for 字符串, 数字, 布尔值, and symbol.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。