Closed
Description
TypeScript Version: 4.0.2
Search Terms: CallableFunction, call, call inference
Expected behavior:
Error reporting what type mismatch in call method:
interface Callable<Return, Arguments extends any[], This = unknown> {
call(thisArg: This, ...args: Arguments): Return;
}
declare function incorrectFunction(a: string, b: number): void;
declare function testFunction(f: Callable<string, [number, boolean], undefined>): void;
testFunction(incorrectFunction);
Actual behavior:
No type check error reporting
Related Issues:
I found only this: #30294
but my example without generic functions
Code
interface Callable<Return, Arguments extends any[], This = unknown> {
call(thisArg: This, ...args: Arguments): Return;
}
declare function correctFunction(a: number, b: boolean): string;
declare function incorrectFunction(a: string, b: number): void;
declare function testFunction(f: Callable<string, [number, boolean], undefined>): void;
// it is Ok
const f1: Callable<string, [number, boolean], undefined> = correctFunction;
testFunction(correctFunction);
// it is not reporting type mismatch
const f2: Callable<string, [number, boolean], undefined> = incorrectFunction;
const f3: Callable<string, [number, boolean], undefined> = () => 1;
testFunction(incorrectFunction);
testFunction((a: number[], b: number[]) => a.concat(b));
f2.call(void 0, 10, true).toLowerCase(); // runtime error here...
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true
}
}