Skip to content

Type never behaves differently when called from object method and top level function #56136

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
victormachado-ada-tech opened this issue Oct 17, 2023 · 1 comment

Comments

@victormachado-ada-tech
Copy link

πŸ”Ž Search Terms

never object method not working

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about never

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/GYVwdgxgLglg9mABMATnAtgFTgBwDICmAbgQDYBi4E8YAFAJQBciYxBKiA3gFCKJQALNAHcWBUQFEUaFLQDkAQwVz63AL7duEBAGcoiOACMAVogC8XXsjToA8iYLQGzViQ48+fQSLGTpcWUVlVT4NDW5QSFgEfgEYHQB1AIBrHWdEPRQYMABzSz5UDGx8NgoqGgZ1TUjoGlj4gBE4Ah0AOTgoJJRk9MzsvI8DEwA6QrsHJ1U1IA

πŸ’» Code

function fromTopLevelFuncion(): never {
  throw new Error('aa')
}

const obj = {
  fromObject(): never {
    throw new Error('aa')
  }
}

function thisWorks(): string {
  fromTopLevelFuncion()
}

function thisDoesNotWork(): string {
  obj.fromObject()
}

πŸ™ Actual behavior

Somehow, when calling a method that returns never typescript does not handles control flow as we expect. There is nothing in the docs about the never type stating that difference in behavior would show up.

πŸ™‚ Expected behavior

Calling a method that returns never should have the same behavior as calling a top level function.

Additional information about the issue

No response

@IllusionMH
Copy link
Contributor

Duplicate of #55154 and many other

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

2 participants