Struggling to define a Typescript interface and implement it in a class.
The issue lies in the method signatures of the interface not being applied to the class as expected.
Below is a simplified example:
export interface Foo {
bar(value: string): void;
}
// ✔️ Typescript error:
// Property 'bar' is missing in type 'MyFoo' but required in type 'Foo'
export class MyFoo implements Foo {
}
// value is inferred as `any` instead of `string`,
// no errors detected with return type mismatch
export class MyFoo implements Foo {
bar(value) { return true; }
}
It appears that although the compiler recognizes the existence of the bar
method, it does not preserve its signature for some reason.