microsoft / microsoft/TypeScript
Type narrowing based on iterator `done` value?
Open
@rbuckton is already working on this.
Since Jun 26, 2019.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
Code
interface MyIterator<T> {
next():
| {
done: false;
value: T;
}
| {
done: true;
value: undefined;
};
[Symbol.iterator](): MyIterator<T>;
}
interface Item { name: string }
function m(iter: MyIterator<Item>) {
for (const it of iter) {
console.log(it.name); // Error here complaining about 'it': Object is possibly 'undefined'.ts(2532)
}
}
Expected behavior:
Actual behavior:
Related Issues:
https://github.com/microsoft/TypeScript/issues/11450 seems related. but here even with --strictNullChecks same error is reported here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.