Skip to content

Implicit Symbol.iterator call does not check additional arguments #57130

Description

@rotu

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

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis 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