Skip to content

Fall back to (Async)IterableIterator if (Async)Generator not found #32303

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

Merged
merged 1 commit into from
Jul 15, 2019

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Jul 8, 2019

Allow generator return type inference to fall back to IterableIterator if Generator can't be found and the return and next types of the generator are compatible with the expected return and next types of IterableIterator.

This improves backwards compatibility for existing generators that may not have the es2015.generators lib included.

Fixes https://github.com/microsoft/TypeScript/pull/32244/files#diff-601ae163618e1a582913605ac0b1b7c1R107

@rbuckton
Copy link
Member Author

rbuckton commented Jul 8, 2019

@DanielRosenwasser: Interested in your feedback. The problem is that Generator (and AsyncGenerator) are under different default libs than IterableIterator (and AsyncIterableIterator), so existing projects could have new errors if they have explicit "lib" settings. The basic idea here is that when we infer a return type for a generator function, if we can't find Generator we will use IterableIterator as the return type if the return and next types are assignment compatible rather than reporting an error. However, we will always use Generator if we can find it.

@rbuckton
Copy link
Member Author

rbuckton commented Jul 8, 2019

@typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 8, 2019

Heya @rbuckton, I've started to run the parallelized community code test suite on this PR at d045eab. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@rbuckton
Copy link
Member Author

rbuckton commented Jul 8, 2019

Other than catching a lot of other diagnostics changes from a different commit, it seems to have addressed https://github.com/microsoft/TypeScript/pull/32244/files#diff-601ae163618e1a582913605ac0b1b7c1R107 from the generator types user test.

@rbuckton
Copy link
Member Author

@weswigham: Can you take a look?

@rbuckton rbuckton merged commit 17762c4 into master Jul 15, 2019
@jakebailey jakebailey deleted the generatorReturnTypeFallback branch November 7, 2022 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants