🔎 Search Terms
Symbol.iterator, for-of, iterable protocol
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Iterator
⏯ Playground Link
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgTwJJQKYCcCGAjANqmAXhgG8AoGSmAKgG0BlBObEXAOgEs0soR0BdABSoAHlCwBBdAHMAXDDABXZhgCUpClS0IOqXABNSMTPNHjMU6TAC+myrdtkA9E+NgYGdHxgALTAAd-VEhfDFQ2GABxEBB9NjIAM29BUEhYERgQBPhkbhx8BiYWdi4MTF4BQVVVci0RNkwyRxcFEA90L3RQ9HCYACFMQ1kAWkFE5NToGAysnJQyvFQau2mGprIgA
💻 Code
constmyIterable={*[Symbol.iterator](extraArg: number){yield{a: extraArg}}}// an error happens here. Good.for(constxofmyIterable[Symbol.iterator]()){x.a}// no error here. Bad :-(for(constxofmyIterable){x.a}🙁 Actual behavior
When using a for-of loop, there is no type error.
🙂 Expected behavior
I expect an error to be reported, as if explicitly calling the [Symbol.iterator] method.
Additional information about the issue
Related to #38388, which points out that resolution does not infer this generic type parameter.
🔎 Search Terms
Symbol.iterator, for-of, iterable protocol
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgTwJJQKYCcCGAjANqmAXhgG8AoGSmAKgG0BlBObEXAOgEs0soR0BdABSoAHlCwBBdAHMAXDDABXZhgCUpClS0IOqXABNSMTPNHjMU6TAC+myrdtkA9E+NgYGdHxgALTAAd-VEhfDFQ2GABxEBB9NjIAM29BUEhYERgQBPhkbhx8BiYWdi4MTF4BQVVVci0RNkwyRxcFEA90L3RQ9HCYACFMQ1kAWkFE5NToGAysnJQyvFQau2mGprIgA
💻 Code
🙁 Actual behavior
When using a for-of loop, there is no type error.
🙂 Expected behavior
I expect an error to be reported, as if explicitly calling the
[Symbol.iterator]method.Additional information about the issue
Related to #38388, which points out that resolution does not infer
thisgeneric type parameter.