Upon compiling the code below, I anticipated encountering TWO errors. However, to my surprise, Typescript compiled it flawlessly 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: The method IFoo.Bar mandates a function argument that accepts a string parameter. Nonetheless, when implementing IFoo in the class Foo, the method Foo.Bar is defined with a function argument that lacks any parameters. This discrepancy should logically trigger a type error.
Expected Error 2: Variable foo is of type IFoo. When calling foo.Bar with a function argument that does not align with the specified parameters of Bar within IFoo, an error should ideally be thrown for violating the interface's definition.
Evidently, there seems to be a lapse in enforcing the function signature types both during implementation and invocation of methods defined by an interface in Typescript. Could someone shed light on why this code compiles without issue?