Skip to content

Type narrowing fails when in unreachable code due to early return #33674

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
TheWyo opened this issue Sep 30, 2019 · 2 comments
Closed

Type narrowing fails when in unreachable code due to early return #33674

TheWyo opened this issue Sep 30, 2019 · 2 comments

Comments

@TheWyo
Copy link

TheWyo commented Sep 30, 2019

TypeScript Version: 3.6.3 (also tested on nightly on playground)

Search Terms: unreachable code narrowing early return

Playground Link: Playground demonstration

Expected behavior:
If you uncomment the early return in the doAThing function (common temp change to disable some stuff for debugging), nothing should happen (allowUnreachableCode is enabled in playground options)

Actual behavior:
TypeScript now fails to perform the type-narrow from the if statement, causing a type error on the assignment line within it. An early return should of course produce an unreachable code error, as it would if the option to allow it wasn't turned on, but I'd expect this to otherwise be side-effect free, TypeScript doesn't seem to stop any other type checks just because the code is unreachable.

Related Issues:
There's a lot of narrowing-related issues so apologies if I happened to miss one, but I couldn't find anything quite related to this, as opposed to other types of narrowing issues.

@nmain
Copy link

nmain commented Sep 30, 2019

Duplicate of #26914

@TheWyo
Copy link
Author

TheWyo commented Sep 30, 2019

Ah, there we go, one I didn't manage to spot. I'll close this in favour of that then, thanks for finding it.

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