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
@uhyo

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions