microsoft / microsoft/TypeScript
Type narrowing based on iterator `done` value?
Aperta
@rbuckton ci sta già lavorando.
Dal 26/6/2019.
Needs Investigation
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.