Skip to content

Iterator return type not constraining typed arrays literalsΒ #46481

Closed
@oguimbal

Description

@oguimbal

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptRescheduledThis 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