Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rotu opened this issue Jan 22, 2024 · 0 comments Β· Fixed by #60321
Closed

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

rotu opened this issue Jan 22, 2024 · 0 comments Β· Fixed by #60321
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@rotu
Copy link

rotu commented Jan 22, 2024

πŸ”Ž 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

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.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jan 22, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.5.0 milestone Jan 22, 2024
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Jul 26, 2024
@rbuckton rbuckton added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Oct 22, 2024
@typescript-bot typescript-bot added Fix Available A PR has been opened for this issue labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants