-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
π 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
π» Code
const myIterable = {
*[Symbol.iterator](extraArg: number) {
yield { a: extraArg }
}
}
// an error happens here. Good.
for (const x of myIterable[Symbol.iterator]()){
x.a
}
// no error here. Bad :-(
for (const x of myIterable){
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
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone