Skip to content
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

Arrow function with never return type does not cause unreachable code when called #37998

Closed
cherryblossom000 opened this issue Apr 16, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@cherryblossom000
Copy link
Contributor

TypeScript Version: 3.8.3

Search Terms: arrow function never unreachable narrowing

Code

const f = (): never => {
    throw new Error()
}
f()
// should be unreachable but isn't
console.log()

Expected behavior:
Unreachable code detected. (7027) warning on line 6 (last line).

Actual behavior:
No warning.

Playground Link: link

Related Issues: #36753, #12825

@IllusionMH
Copy link
Contributor

IllusionMH commented Apr 16, 2020

As mentioned in linked #36753 (and many other e.g. #37472 (comment)) - it's design limitation.
Your const f needs explicit type annotation to participate in CFA.
const f: () => never = ...

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants