Skip to content

Incorrect type-error with interface and throwsΒ #51102

Closed
@thedrlambda

Description

@thedrlambda

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions