FunctionType is not verify on build

Topics: General
Jun 2, 2013 at 3:19 PM
Hi,

I don't understand why the following code passed :
class Class1 {
    constructor() {  
        this.add(this.test);
    }

    public test():bool  {
        return true;
    }

    public add(callback: (value: number) => any) {

    }
}
The add method waits for a parameter callback of type (value: number) => any.
I call add method with a type ()=>bool, and it's work.

Why ?
Coordinator
Jun 2, 2013 at 6:40 PM
I believe it's valid to pass a function that takes fewer arguments in because it's simply not using the parameters. The opposite would be a problem, if you passed a function that required parameters to something that wouldn't be able to provide them. As in this example, which gives an error:
class Class1 {
    constructor() {  
        this.add(this.test);
    }

    public test(value: number):bool  {
        return true;
    }

    public add(callback: () => any) {

    }
}
Developer
Jun 4, 2013 at 7:11 PM
You may be interested in Ander's previous reply to a similar topic: https://typescript.codeplex.com/discussions/428458