Closed
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
.