查找: 错误函数 Overload
找错误 中等
题目
这个 code 有类型错误. 查找 mistake:
代码
function process(x: string): string;
function process(x: number): number;
function process(x: string | number): string | number {
return x;
}
const result = process(true);
提示
检查什么类型 overloads 接受对比什么是 是通过.
解释
函数 overloads 仅接受 字符串 or 数字, 但 真 (布尔值) 是通过. TypeScript 错误: 否 overload matches 这个 call. implementation signature 是不 directly callable — 仅 overload signatures 是. Fix: 通过字符串 or 数字, or 添加布尔值 overload.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。