Skip to content
New issue

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

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

Already on GitHub? # to your account

set.values().next() has wrong type #43750

Closed
thesoftwarephilosopher opened this issue Apr 20, 2021 · 4 comments Β· Fixed by #58243
Closed

set.values().next() has wrong type #43750

thesoftwarephilosopher opened this issue Apr 20, 2021 · 4 comments Β· Fixed by #58243
Assignees

Comments

@thesoftwarephilosopher
Copy link

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

Happens in both versions 4.2.3 and 4.3.0-beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const s = new Set<string>();
s.values().next().value;

πŸ™ Actual behavior

Type of value is any.

πŸ™‚ Expected behavior

Type of value should probably be string | undefined or something.

@nmain
Copy link

nmain commented Apr 20, 2021

next() returns a discriminated union so you can get what you want:

const v = s.values().next();
if (v.done) {
  v.value; // any
} else {
  v.value; // string
}

It would make more sense for v.value to be typed as void or undefined in the done case though.

@MartinJohns
Copy link
Contributor

@nmain Or never.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Apr 20, 2021
@RyanCavanaugh
Copy link
Member

@rbuckton I believe we have a duplicate of this?

@nmain
Copy link

nmain commented Apr 20, 2021

Ahh yes, this seems to be #33353
Search terms: iteratorresult return

@rbuckton rbuckton removed the Needs Investigation This issue needs a team member to investigate its status. label Oct 22, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants