Reputation: 33
I´m currently using Typescript 3.6.4.
Code:
const a = () => {
console.log("what ever");
}
const b = (aprop:(aparam:string)=> void) => {
aprop("myparam");
}
const c = () => {
b(a)
};
c()
Somehow TS is not showing any error compiling this. Although "a" doesn't take a parameter "b" can savely call "a" with a parameter.
But this would throw an error (Expected 0 arguments, but got 1):
const a=()=>{
console.log("what ever")
}
const b=()=>{
a("x");
}
It looks like a bug to me but maybe there is something I'm missing here.
Upvotes: 1
Views: 163
Reputation: 440
const a: (a: string) => void = () => {
console.log("no matter");
}
see https://www.typescriptlang.org/docs/handbook/type-compatibility.html#comparing-two-functions
() => void
is compatible with (a:string) => void
, because the former function doesn't need an parameter.
The parameter won't be used when the function is called, it won't cause error any more.
Upvotes: 1