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

union types narrowed incorrectly by assertion functions and type predicate functions #43825

Closed
DetachHead opened this issue Apr 26, 2021 · 3 comments Β· Fixed by #49625
Closed

union types narrowed incorrectly by assertion functions and type predicate functions #43825

DetachHead opened this issue Apr 26, 2021 · 3 comments Β· Fixed by #49625

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Apr 26, 2021

Bug Report

πŸ”Ž Search Terms

union types narrowed incorrectly

πŸ•— Version & Regression Information

v4.3.0-dev.20210426

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function assert<T>(value: any): asserts value is T

declare const foo: number | string | boolean

assert<1 | string>(foo)

const bar = foo //string

πŸ™ Actual behavior

foo is narrowed to string

πŸ™‚ Expected behavior

foo should be narrowed to 1 | string

@ethan-xd
Copy link

allan

@jcalz
Copy link
Contributor

jcalz commented Apr 26, 2021

Duplicate of #31156?

@whzx5byb
Copy link

See Issues with narrowing unions by union types in #32158. I think it's a design limitation?

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