function call(name: "showToast", data: { content: string }): void;
function call(name: "showConfirm", data: { age: number }): void;
function call(name: any, data: any): void {}
call("showToast", {
content: 123
})
能够根据定位参数name
的值,给出data
参数不匹配的提示吗?
想要做到直接提示showToast
的content
类型错误
No overload matches this call
已经说明了重载的检测方式是模式对比,而不是确定一个模式然后内部检查。假设签名为A+B,在你看来写了A+C应该报C错误,但这里也有可能存在一个D+C的重载;又或者值是对的,而现有重载并未包含所有格式。TS很难猜到你的意图