Closed
Description
Bug Report
π Search Terms
interface, throw
π Version & Regression Information
My version is 4.8.2
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about throw and type-error
β― Playground Link
Playground link with relevant code
π» Code
interface SomeInterface {
foo(): string | undefined;
}
class SomeInterfaceDummy implements SomeInterface {
foo() /* : never */ {
throw "Should not be called";
// return "";
}
}
class SomeInterfaceStub extends SomeInterfaceDummy {
foo() {
return "stub";
}
}
π Actual behavior
There is no way to type-check the code above. The return type is inferred as void (I expected never
). Adding the out-commented return gives the correct return type but errors with "unreachable code." Putting the return type : never
explicitly means the inheriting method doesn't compile.
π Expected behavior
Body that throws is inferred to have type never
and never <: any
so there should be no errors.