打字稿:使用错误的参数计数没有警告

Typescript: No warning using wrong parameter count

我目前使用的是 Typescript 3.6.4。

代码:

const a = () => {
  console.log("what ever");
}
const b = (aprop:(aparam:string)=> void) => {
  aprop("myparam");
}
const c = () => {
  b(a)
};

c()

不知何故,TS 在编译时没有显示任何错误。虽然 "a" 不带参数 "b" 可以用参数调用 "a" 。

但这会引发错误(预期 0 个参数,但得到 1 个):

const a=()=>{
    console.log("what ever")
}

const b=()=>{
    a("x");
}

对我来说这看起来像是一个错误,但也许我在这里遗漏了什么。

已更新

const a: (a: string) => void = () => {
    console.log("no matter");
}

https://www.typescriptlang.org/docs/handbook/type-compatibility.html#comparing-two-functions

() => void兼容(a:string) => void,因为前一个函数不需要参数。
调用函数时不会使用参数,不会再报错