microsoft / microsoft/TypeScript

Improve Iterator Helper Type Signatures

Aperta
#59,926 10 commenti 1 reazione 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 20/9/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

⚙ Compilation target

ESNext

⚙ Library

esnext.iterator.d.ts

Missing / Incorrect Definition
  • Iterator.from(value: Iterator) - PR #59927
    • value iterator argument with TNext other than undefined should be accepted; this is a bad idea; my mistake
    • Since IteratorObject instances (objects whose prototype is Iterator.prototype) are not wrapped by Iterator.from, we could add an Iterator.from overload to represent those cases and pass through all generic type parameters: from<T, TReturn = any, TNext = any>(value: IteratorObject<T, TReturn, TNext>): IteratorObject<T, TReturn, TNext>;
    • TReturn type should be passed through from the argument to the return type
  • Iterator helper intermediate operators (filter, map etc) do not propagate the return value of their source iterator and should have TReturn set to undefined
    • This is already the case in the current declarations
  • Iterator objects returned from Iterator.from and the other built-in iterators returned from Array.values etc always have a return method (built-in iterators returned from Array.values etc also always have a throw method) thanks to @bakkot for the clarification
    • There is no way that I am aware of to express this behavior in TypeScript with the current definition of IteratorObject without also forcing user-defined classes extending from the javascript Iterator class to also implement the return method, which would be wrong. The impact on client code is minimal as the Iterator object's return method can always be called safely using the return!() notation.
Sample Code
https://github.com/nikolaybotev/iteratorhelpersdemo
Documentation Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator

and

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.