Closed
Description
Bug Report
π Search Terms
error ignores declared interface
π Version & Regression Information
Tested in the Playground and the issue occurs in 3.3.3 in the playground with 4.4.2 and nightly (4.5.0-dev20210910).
β― Playground Link
π» Code
interface Logger {
log(level: number, message: string): void;
}
class ConsoleLogger implements Logger {
log(message: string): void {} // Expected (Property 'log' in type 'ConsoleLogger' is not assignable to the same property in base type 'Logger'.)
}
function getLogger(): Logger {
return new ConsoleLogger(); // Unexpected (Type 'ConsoleLogger' is not assignable to type 'Logger'.)
}
π Actual behavior
The TypeScript compiler reports an error in the getLogger()
function.
This is not a major problem, since fixing the root cause also gets rid of the error. But it's not ideal because the second error is mostly noise.
This feels analogous to this situation (playground link):
function f(): number {
return 'x'; // Error, as expected.
}
Math.abs(f()); // No error, as expected.
π Expected behavior
I would expect there to be no error reported in the getLogger()
function.