The type checker seems fine with this use of a generic type in a function parameter:
functioncallMe<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:
functioncallMeConcrete(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));
The type checker seems fine with this use of a generic type in a function parameter:
If
callMeis made non-generic and uses hardcoded types then an error is issued as expected: