Happens in both versions 4.2.3 and 4.3.0-beta
Playground link with relevant code
const s = new Set<string>(); s.values().next().value;
Type of value is any.
value
any
Type of value should probably be string | undefined or something.
string | undefined
next() returns a discriminated union so you can get what you want:
next()
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.
v.value
void
undefined
Nicholai Main (@nmain) Or never.
never
Ron Buckton (@rbuckton) I believe we have a duplicate of this?
Ahh yes, this seems to be #33353 Search terms: iteratorresult return
Activity
nmain commentedon Apr 20, 2021
next()returns a discriminated union so you can get what you want:It would make more sense for
v.valueto be typed asvoidorundefinedin the done case though.MartinJohns commentedon Apr 20, 2021
Nicholai Main (@nmain) Or
never.RyanCavanaugh commentedon Apr 20, 2021
Ron Buckton (@rbuckton) I believe we have a duplicate of this?
nmain commentedon Apr 20, 2021
Ahh yes, this seems to be #33353
Search terms: iteratorresult return