Skip to content

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

@shigma

Description

@shigma

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[]

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions