@@ -40,25 +40,24 @@ interface IteratorZipLongestOptions<T> {
4040interface IteratorZipStrictOptions {
4141 /**
4242 * Requires every input to yield the same number of values.
43+ * If not, a `TypeError` will be thrown when an input is exhausted before others.
4344 */
4445 mode : "strict" ;
4546}
4647
47- type IteratorZipOptions < T > = IteratorZipShortestOptions | IteratorZipLongestOptions < T > | IteratorZipStrictOptions ;
48+ type IteratorZipOptions < T > =
49+ | IteratorZipShortestOptions
50+ | IteratorZipLongestOptions < T >
51+ | IteratorZipStrictOptions ;
4852
4953type IteratorInput < T > = Iterable < T > | Iterator < T > ;
5054
51- type IteratorYield < T extends IteratorInput < unknown > > =
52- T extends Iterable < infer U , any , any > ? U :
53- T extends Iterator < infer U , any , any > ? U :
54- never ;
55+ type IteratorInputTuple = readonly [ ] | readonly [ IteratorInput < unknown > , ...IteratorInput < unknown > [ ] ] ;
5556
56- type IteratorZipResult < T extends readonly IteratorInput < unknown > [ ] > = {
57- - readonly [ K in keyof T ] : IteratorYield < T [ K ] > ;
58- } ;
57+ type IteratorYield < T > = T extends IteratorInput < infer U > ? U : never ;
5958
60- type IteratorZipKeyedResult < T extends { readonly [ K in keyof T ] : IteratorInput < unknown > } > = {
61- - readonly [ K in keyof T ] : IteratorYield < T [ K ] > ;
59+ type IteratorZipResult < T , TExtra = never > = {
60+ - readonly [ K in keyof T ] : IteratorYield < T [ K ] > | TExtra ;
6261} ;
6362
6463declare global {
@@ -97,20 +96,24 @@ declare global {
9796 * @param iterables An iterable of iterators or iterables to zip.
9897 * @param options Controls how differing input lengths are handled.
9998 */
100- zip < T extends readonly IteratorInput < unknown > [ ] | [ ] > ( iterables : T , options ?: IteratorZipOptions < NoInfer < Partial < IteratorZipResult < T > > > > ) : IteratorObject < IteratorZipResult < T > , undefined , unknown > ;
99+ zip < T extends IteratorInputTuple > ( iterables : T , options : IteratorZipLongestOptions < NoInfer < IteratorZipResult < T > > > & { padding : NoInfer < IteratorZipResult < T > > ; } ) : IteratorObject < IteratorZipResult < T > , undefined , unknown > ;
100+ zip < T extends readonly IteratorInput < unknown > [ ] | [ ] > ( iterables : T , options ?: IteratorZipShortestOptions | IteratorZipStrictOptions ) : IteratorObject < IteratorZipResult < T > , undefined , unknown > ;
101+ zip < T extends readonly IteratorInput < unknown > [ ] | [ ] > ( iterables : T , options : IteratorZipOptions < NoInfer < Partial < IteratorZipResult < T > > > > ) : IteratorObject < IteratorZipResult < T , undefined > , undefined , unknown > ;
101102
102103 /**
103104 * Creates an iterator whose values are arrays containing values yielded at the same position by each input iterator or iterable.
104105 * @param iterables An iterable of iterators or iterables to zip.
105106 * @param options Controls how differing input lengths are handled.
106107 */
107- zip < T extends IteratorInput < unknown > > ( iterables : Iterable < T > , options ?: IteratorZipOptions < NoInfer < Iterable < IteratorYield < T > > > > ) : IteratorObject < IteratorYield < T > [ ] , undefined , unknown > ;
108+ zip < T extends IteratorInput < unknown > > ( iterables : Iterable < T > , options ?: IteratorZipShortestOptions | IteratorZipStrictOptions ) : IteratorObject < IteratorYield < T > [ ] , undefined , unknown > ;
109+ zip < T extends IteratorInput < unknown > > ( iterables : Iterable < T > , options : IteratorZipOptions < NoInfer < Iterable < IteratorYield < T > > > > ) : IteratorObject < ( IteratorYield < T > | undefined ) [ ] , undefined , unknown > ;
108110
109111 /**
110112 * Creates an iterator whose values are objects containing values yielded at the same position by each iterator or iterable in the input object.
111113 * @param iterables An object whose enumerable own properties contain iterators or iterables to zip.
112114 * @param options Controls how differing input lengths are handled.
113115 */
114- zipKeyed < T extends { readonly [ K in keyof T ] : IteratorInput < unknown > } > ( iterables : T , options ?: IteratorZipOptions < NoInfer < Partial < IteratorZipKeyedResult < T > > > > ) : IteratorObject < IteratorZipKeyedResult < T > , undefined , unknown > ;
116+ zipKeyed < T extends object > ( iterables : T & Record < keyof T , IteratorInput < unknown > > , options ?: IteratorZipShortestOptions | ( IteratorZipLongestOptions < NoInfer < IteratorZipResult < T > > > & { padding : NoInfer < IteratorZipResult < T > > ; } ) | IteratorZipStrictOptions ) : IteratorObject < IteratorZipResult < T > , undefined , unknown > ;
117+ zipKeyed < T extends object > ( iterables : T & Record < keyof T , IteratorInput < unknown > > , options : IteratorZipOptions < NoInfer < Partial < IteratorZipResult < T > > > > ) : IteratorObject < IteratorZipResult < T , undefined > , undefined , unknown > ;
115118 }
116119}
0 commit comments