microsoft / microsoft/TypeScript
Improve Iterator Helper Type Signatures
Offen
@rbuckton arbeitet bereits daran.
Seit 20.9.2024.
Needs Investigation
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
⚙ Compilation target
ESNext
⚙ Library
esnext.iterator.d.ts
Missing / Incorrect Definition
-
Iterator.from(value: Iterator)- PR #59927-
this is a bad idea; my mistakevalueiterator argument withTNextother thanundefinedshould be accepted; - Since
IteratorObjectinstances (objects whose prototype isIterator.prototype) are not wrapped byIterator.from, we could add anIterator.fromoverload 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>; -
TReturntype should be passed through from the argument to the return type
-
- Iterator helper intermediate operators (
filter,mapetc) do not propagate the return value of their source iterator and should haveTReturnset toundefined- This is already the case in the current declarations
-
Iterator objects returned fromthanks to @bakkot for the clarificationIterator.fromand the other built-in iterators returned fromArray.valuesetc always have areturnmethod (built-in iterators returned fromArray.valuesetc also always have athrowmethod)- There is no way that I am aware of to express this behavior in TypeScript with the current definition of
IteratorObjectwithout also forcing user-defined classes extending from the javascriptIteratorclass to also implement thereturnmethod, which would be wrong. The impact on client code is minimal as the Iterator object'sreturnmethod can always be called safely using thereturn!()notation.
- There is no way that I am aware of to express this behavior in TypeScript with the current definition of
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.