microsoft / microsoft/TypeScript

Iterator Helpers: `return` method typing is weaker than ideal

Aperta
#60,176 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

⚙ Compilation target

ESNext

⚙ Library

esnext.iterator.d.ts

Missing / Incorrect Definition

The return method always exists on iterators returned by Iterator.from (iter in below code) and iterators returned by Iterator Helpers methods (iter2 in below code).

However, it is defined as optional in the current definition. This could be improved.

Please note that you can't just add a non-optional return method definition to the IteratorObject type -- iterators returned by builtin methods other than Iterator Helpers don't have that method (iter3).

P.S. if you are interested in a motivating example, I don't have one. Sorry 🤪

Sample Code
const iter = Iterator.from({ next() { return { done: false, value: 0 }} });

iter.return(); // should not error

const iter2 = iter.map(x => x);

iter2.return(); // should not error

const iter3 = [].values();

iter3.return(); // Note: this error IS correct

Playground

Documentation Link

https://tc39.es/proposal-iterator-helpers/

Spec states that below objects always have the return method:

  • %WrapForValidIteratorPrototype%
  • %IteratorHelperPrototype%

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in esnext.iterator.d.ts e esamina le definizioni di IteratorObject, Iterator.from e Iterator Helpers confrontandole con il codice di esempio. Verifica il comportamento previsto in base alla specifica Iterator Helpers collegata: Iterator.from e i risultati degli helper dovrebbero consentire return(), mentre [].values() dovrebbe continuare a rifiutarlo. Il lavoro è completato quando le dichiarazioni distinguono questi casi senza introdurre un errore per iter3.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
58/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.