Skip to content

Iterator return type not constraining typed arrays literals #46481

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
oguimbal opened this issue Oct 22, 2021 · 1 comment
Closed

Iterator return type not constraining typed arrays literals #46481

oguimbal opened this issue Oct 22, 2021 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@oguimbal
Copy link

Bug Report

πŸ•— Version & Regression Information

It has always been there. (tested with every Typescript version available in the playground since the support or typing for iterator return types)

⏯ Playground Link

πŸ‘‰ Reproduction link in playground

πŸ’» Code

export type It = Iterator<[string, number], [string, number]>;

function *it(): It {
    yield ['', 0]; // this works βœ”οΈ
    return ['', 0]; // this fails ❌
}

πŸ™ Actual behavior

The return statement does not constraint the array literal to the right type. Instead, it takes its... I dont know how to put it... its "natural" type ?

πŸ™‚ Expected behavior

Both yield & return statements should compile.

πŸ‘‰ Workaround: Force the array to be correctly typed via return ['', 0] as const.

@oguimbal oguimbal changed the title Iterator return type not constraining typed arrays Iterator return type not constraining typed arrays literals Oct 22, 2021
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Nov 4, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.6.0 milestone Nov 4, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 13, 2022
@rbuckton
Copy link
Contributor

This looks to have been fixed in TypeScript 4.8 as a result of #49736.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

4 participants