查找: 错误 Utility 类型
找错误 中等
题目
这个 code 有类型错误. 查找 mistake:
代码
interface User { id: number; name: string; email: string; }
type Update = Pick<User, "id" | "name">;
const update: Update = { name: "Bob", email: "[email protected]" };
提示
检查哪个属性选取选择对比什么对象 provides.
解释
选取<用户, "id" | "name"> type only has id and name properties — email is not included. The object has email which is not in the picked type, and is missing id. TypeScript errors: 'email' does not exist in type 'Update' and 'id' is missing. Fix: use 选取<用户, "name" | "email"> or provide 正确属性.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。