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

Failure to narrow conditional type after guard #47168

Closed
schuelermine opened this issue Dec 16, 2021 · 2 comments
Closed

Failure to narrow conditional type after guard #47168

schuelermine opened this issue Dec 16, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@schuelermine
Copy link

schuelermine commented Dec 16, 2021

Bug Report

πŸ”Ž Search Terms

conditional type guard

πŸ•— Version & Regression Information

This seems to not be a regression at all.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type X<T> = A<T> | B<T>
type A<T> = {type: "a", value: T}
type B<T> = {type: "b", value: T}
type R<T,Y extends X<T>> = Y extends B<T> ? T : void
function f<T,Y extends X<T>>(y: Y): R<T,Y> {
    if (y.type === "b") {
        return y.value
    } else return
}

πŸ™ Actual behavior

TS complains about y.value and else return.

πŸ™‚ Expected behavior

They should be accepted.

@jcalz
Copy link
Contributor

jcalz commented Dec 16, 2021

Duplicate of #33912

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 3, 2022
@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