Skip to content

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

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
uhyo opened this issue Aug 27, 2021 · 0 comments Β· Fixed by #49736
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@uhyo
Copy link
Contributor

uhyo commented Aug 27, 2021

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.

@uhyo uhyo 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 Aug 27, 2021
@andrewbranch andrewbranch added the Bug A bug in TypeScript label Aug 27, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.5.0 milestone Aug 27, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 15, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants