I'm trying to write a Typescript interface, then write a class that implements that interface.
The problem is that I can't seem to get the method signatures from the interface to apply to the class.
Here's a slimmed-down example:
export interface Foo {
bar(value: string): void;
}
export class MyFoo implements Foo {
// ✔️ 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`,
// and there aren't any errors with the return type mismatch
bar(value) { return true; }
}
It seems that the compiler is aware that the bar method should exist, but doesn't preserve the signature of it for some reason.