Skip to content

No contextual typing on yield expression when generator function is contextually typed as union of normal function and generator functionΒ #45596

Closed

Description

@uhyo

Bug Report

πŸ”Ž Search Terms

generator function union contextual typing yield

πŸ•— Version & Regression Information

4.1.5, 4.4.2

  • This changed between versions 4.0.5 and 4.1.5

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type FuncOrGeneratorFunc = () => (number | Generator<(arg: number) => void, any, void>)

const f: FuncOrGeneratorFunc = function*() {
  // Error: Parameter 'num' implicitly has an 'any' type.
  yield (num) => console.log(num);
}

πŸ™ Actual behavior

A noImplicitAny error is reported.

Note: the same happens for async generator functions too.

πŸ™‚ Expected behavior

Type of num is inferred as number. This is the behavior of TS 4.0.

Activity

  1. changed the title [-]No contextual typing on yield expression when async generator function is contextually typed as union of async function and async generator function[/-] [+]No contextual typing on yield expression when generator function is contextually typed as union of normal function and generator function[/+] on Aug 27, 2021
  2. added
    Rescheduled
    on Dec 15, 2021
  3. added
    Fix Available
    on Jun 29, 2022
  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFix AvailableRescheduled

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions