Closed
Description
The type checker seems fine with this use of a generic type in a function parameter:
function callMe<T>(value: T, fn: (value: T) => void) : void {
fn(value);
}
// No error!
callMe(17, (n: string) => console.log(n) );
If callMe
is made non-generic and uses hardcoded types then an error is issued as expected:
function callMeConcrete(value: number, fn: (value: number) => void) : void {
fn(value);
}
// Error as expected!
// TS2345: Argument of type '(n: string) => void' is not assignable to parameter of type '(value: number) => void'.
callMeConcrete(17, (n: string) => console.log(n) );