Skip to content

Interfaces don't guide inference for functions that end in throw #51027

Closed
@appreciate-devon

Description

@appreciate-devon

Bug Report

🔎 Search Terms

implements doesn't influence throw
function that only throws implicitly returns void

(I did find #7538 but there were no associated issues)

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries. I tried 4.3.5 as well as next

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Foo {
  func(): number
}

class Bar implements Foo {
  func() {
    throw new Error("Bogus")
  }
}

🙁 Actual behavior

Property 'func' in type 'Bar' is not assignable to the same property in base type 'Foo'.
  Type '() => void' is not assignable to type '() => number'.
    Type 'void' is not assignable to type 'number'.

🙂 Expected behavior

I expected () => number to be used to inform Bar's definition for func(), since the interface sets the lower bound for acceptable return values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions