Skip to content

typescript doesn't check callback signatures #9300

@fernandezpablo85

Description

@fernandezpablo85

TypeScript Version:

1.7.5

Code

type cb = (a:number, b:number) => number;

function foo(callback: cb): void {
    callback(1,2);
}

foo(function(a, b){return 1;}); // this is OK.
foo(function(a){return 1;}); // this should fail.
foo(function(){return 1;}); // this should fail.

Expected behavior:

First call should compile. The rest shouldn't.

Actual behavior:

All calls compile cleanly.

Additional note
This is what happens, for example, with Array.prototype.sort

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions