This project is read-only.

Call signature checking for function types

Topics: Code Checkins
Oct 24, 2012 at 5:14 AM
Edited Oct 24, 2012 at 5:14 AM

I was experimenting with call signature declarations to force callbacks to be implemented correctly, but I don't seem to get the results I thought declaring call signatures would get me.

Consider the following:

interface SuccessCallback {
    (status: number): number;

function service(success: SuccessCallback) {

function successHandlerA() {    

function successHandlerB() {
    return 1;

service(successHandlerA); // compliler complains
service(successHandlerB); // compiles ok
service(() => {}); // compiles ok
service(() => { return 'a'; }); // compiler complains
service(function () { }); // compiles ok
service(function () { return 'a'; }); // compiler complains 

1) It seems the compiler does not care to check parameter of the call.

2) It seems the compiler only cares to check the function return type.

3) Looks like the compiler only checks the return type of anonymous functions if they actually return something.

Oct 29, 2012 at 3:49 PM

Seems like a bug for me!

But I think you chose the wrong discussion forum. You can edit your thread (AFAIK) in order to move it to the General forum.

You can just create a new issue, too: Issue Tracker