Skip to content

CalableFunction interface can be assigned to variable with another 'call' method signature #41135

Closed
@bingo347

Description

@bingo347

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
  }
}

Playground Link: https://www.typescriptlang.org/play?noUnusedLocals=true&noUnusedParameters=true&esModuleInterop=false&declaration=false&experimentalDecorators=false&emitDecoratorMetadata=false&target=7&jsx=0#code/JYOwLgpgTgZghgYwgAgMJwDYbgIwxAHgCUIwBXKEAGmQEEoBzMgWwnAGdkIAPSEAE05wQATwDaAXRoAVABbBOAXmRkQAaxAB7AO4gAfMgDeAKGRnkCTBgAUYee3oMAXMjkKaAOi9xG7F45Y2MHYAShcSckoAbmMAX2NjfggEbCgUGFUEMGBNEAtNKDSsgDFM7NzrOBcQFhxoGhwXHE1NfGEw5HYwKFAGGKSUn3SynLzQBAKisFKQLNHKly6ekAYG6troDoA3TWB+fuTU4dnyvMgumbmKmBd0LFx8AiXemjEa5jqoBpa2kCkVAQQGCgCD8PTbXb7BIAemhyGAYHhnAA8mpjBMQF1kDAAIy3KwPQjPFavd6fb6tCDCf6qJLAkCggzKCaFZLTEa5GLndkneYsqaXU4hGLGWHwxEKZBaRFpAAOBWyK2QYBEspQzAUzDgYAQsnRuSxMAATPj7ngid0Xsg3hsvshmpTqTRaUCQWDkMpxpM2YLRjEMYaAMym7Dmp6WknWsn1e0-Kl-Z2A+mMj3IawhD0GHFciAXDkgaxe1klfPC4zc30VBZS22SNY1j7QSQZxQGOAeDGWMDWHAhMvGjtWaw7PbIAAMNBxE+VUDIEBCHjAmgAMjpoOh2BB01FkGLZ+BgKwuIUCshZNAIF4PDC4Qikcg5QresYiwL84OsMPIePJ9PunOFyXVdtHXOBN23G98nANJuDgZhZXwZBtARWR8mLGUIHlKBFQYUU4SSZgDW6bVemVWRtTIyVJXldh2GAc1sVPFU1XYBAellMAX3AaB4CQNBvSyAhpAMExzGQVg7E0fhKkYFxpAhPYYniAMJWCAB1Ao1FuASwHDZYGCZIxTHMCTZCk6wAH0fGcBtPgU-gjHiWIoiAA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions