Predict Conditional 类型输出
预测输出 中等
题目
什么做 这个 code print?
代码
type IsString<T> = T extends string ? "yes" : "no";
const a: IsString<string> = "yes";
const b: IsString<number> = "no";
console.log(a);
console.log(b);
提示
Conditional 类型 resolve based on whether T extends 条件.
解释
IsString<字符串> resolves 到 "yes" 因为字符串 extends 字符串. IsString<数字> resolves 到 "no" 因为数字做 不 extend 字符串. 变量 and b 是 assigned accordingly. 输出: 是 and 否.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。