Use `Iterable` instead of `Iterator` for generator functions
https://github.com/dudykr/stc/blob/e69d14c1b30473f73bc8873400e950d44a047e64/crates/stc_ts_file_analyzer/tests/tsc/types/builtin/generator/bad/.1.ts#L1-L2
This should fail because a generator function uses the item from Iterable as yield type.
i.e., g3 is inferred to emit a string as an item, and the inferred generator (Generator<number, any, undefined>) is assigned to BadGenerator.
It should file with
tests/tsc/types/builtin/generator/bad/1.ts:2:24 - error TS2322: Type 'Generator<string, any, undefined>' is not assignable to type 'BadGenerator'.
The types returned by 'next(...)' are incompatible between these types.
Type 'IteratorResult<string, any>' is not assignable to type 'IteratorResult<number, any>'.
Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorResult<number, any>'.
Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorYieldResult<number>'.
Type 'string' is not assignable to type 'number'.
But currently, stc fails to emit an error because stc uses the Iterator interface instead of the Iterable interface while inferring the yield type.
https://github.com/dudykr/stc/blob/e69d14c1b30473f73bc8873400e950d44a047e64/crates/stc_ts_file_analyzer/src/analyzer/stmt/return_type.rs#L176-L181
Hi, I want to take this issue🙋♂️ @kdy1
Cool, thanks!
@timeTravelCYN Are you working on it? Feel free to tell me if you want me to take it (or simply unassign)
Do we have to implement get_iterable_element_type from scratch including all functions related with iterable like get_next_value_type_of_iteratable?
Not sure, but I think we can reuse many parts of it. Maybe we can extract some common logic to a function
Closing as this is already fixed