-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone