interface IConverter {
convert(value: number): string
}
class Converter implements IConverter {
convert(): string { // no error?
return '';
}
}
const v1: IConverter = new Converter();
const v2: Converter = new Converter();
v1.convert(); // error, convert has parameter, although Converter's convert doesn't expect one
v2.convert(); // ok, convert has no parameters, although Converter implements IConverter which should have a parameter
Converter
is supposed to implement IConverter
, which includes a method that expects one parameter. However, in the definition of Converter
, this parameter is missing. It is intriguing why TypeScript compiler does not flag this discrepancy as an error when implementing interfaces.