I was expecting TWO errors when compiling the code below, but typescript compiles it without any errors.
interface IFoo{
Bar(callback: (arg:string) => void):void;
}
class Foo implements IFoo {
public Bar(callback: () => void):void{
callback();
}
}
var foo: IFoo;
foo = new Foo();
foo.Bar(() => {
console.log("Hi");
})
Expected Error 1: IFoo.Bar requires a function argument which itself takes a string argument. However, when Foo implements IFoo, Foo.Bar is declared to take a function argument with NO arguments. I would expect this to be a type error.
Expected Error 2: foo is of type IFoo. foo.Bar is called with a function argument that takes no arguments, contrary to the definition of Bar in IFoo. I would expect this to be a type error.
So both when declaring a concrete implementation of an interface method, and also when calling the interface method, it seems that the type of the function signature is not being enforced.
Clearly I am misunderstanding how typescript handles type checking of function arguments declared by an interface. Can someone explain why this compiles without error?