Skip to content

Type of return value of yield cannot be inferred from explicitly declared TNextΒ #63313

@zimtsui

Description

@zimtsui

πŸ”Ž Search Terms

generator tnext yield type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried between 5.0.4 ~ 6.0.2

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.2&filetype=ts#code/IYIwzgLgTsDGEAJYBthjAgggg3gXwChRIZ4lV0EAhXQggUwA8AHAeykQDMBXAO3gCWrXggBUnADzAETCPV4ATDJgA0CEDMZzFGKgD4AFDADuALgQBxefRgR2UhAB91a3vQBuN19wC2IG3oAlOZWbrb20s4grh5eCLy+-lB6uAQI6UjCkAiMCAC8CCYAdG5aBoFF7sDI3PQA3GkZApwIBrkCvJDA-PSsLZiBtDLIYPQIEAAWUKzG8fSzAKJQ01DlDRkIyPSIrNwQzHvmker5OesZnOytdXWDOI0b6bBZiAKnAJ4C9MgKCLv7e3Ojz+ewOiAKxVKEAMAgqVRq9QeCEIhCAA

πŸ’» Code

abstract class A {}
abstract class B {}

export function *f<a extends A, b extends B>(raw: Generator<a | b, never, number>): Generator<a | b, never, number> {
    const x = raw.next().value;
    if (x instanceof A) {} else throw new Error();
    let output: a | b = x;
    for (;;) {
        const i = yield output;
        output = raw.next(i).value;
    }
}

πŸ™ Actual behavior

The type of i should be infered as number because the function signature is explicitly declared.

πŸ™‚ Expected behavior

'i' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions