Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
appreciate-devon opened this issue Oct 2, 2022 · 3 comments
Closed

Comments

@appreciate-devon
Copy link

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.

@fatcerberus
Copy link

Method types aren’t currently inferred based on implements or extends. Related to #32082

@MartinJohns
Copy link
Contributor

And the function ending in a throw is irrelevant. This errors as well:

interface Foo {
  func(): 1
}

export class Bar implements Foo {
  func() {
    return 1
  }
}

@blast-hardcheese
Copy link

Ah, thank you. Seeing as my issue is completely covered by the other issue, I'll watch that and close this.

Unrelated: I've been using TS on and off for close to ten years, thanks very much to everyone involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants