Skip to content

Bug: incorrect contextual typing on yield expression of generator function as discriminate of a union #51187

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
shigma opened this issue Oct 15, 2022 · 1 comment Β· Fixed by #51196
Assignees
Labels
Fix Available A PR has been opened for this issue

Comments

@shigma
Copy link

shigma commented Oct 15, 2022

Bug Report

πŸ”Ž Search Terms

generator function union contextual typing yield expression

πŸ•— Version & Regression Information

4.8.4

⏯ Playground Link

Playground link with relevant code

image

πŸ’» Code

type Action = () => (Generator<string, string, string[]> | string)

const b: Action = function* () {
    // expect `string[]`, actual `never`
    const c = yield ''
    return ''
}

πŸ™ Actual behavior

never

πŸ™‚ Expected behavior

string[]

@shigma
Copy link
Author

shigma commented Oct 15, 2022

Other cases:

unknown:

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue
Projects
None yet
3 participants