Skip to content

Commit f073d90

Browse files
authored
fix(iterateFormatted): function's type signature does not not handle maybe-async-iterable kind of types correctly (#57)
1 parent 9f6e47a commit f073d90

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/common/AsyncIterableChannel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AsyncIterableChannel<T, TInit = T> {
4545
const whenIteratorClosed = promiseWithResolvers<IteratorReturnResult<undefined>>();
4646
return {
4747
next: () => {
48+
// TODO: Should every iterator of this kind here yield `this.#currentValue` first?...
4849
return Promise.race([this.#nextIteration.promise, whenIteratorClosed.promise]);
4950
},
5051
return: async () => {

src/iterateFormatted/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ export { iterateFormatted };
7070
* If `source` is a plain value and not an async iterable, it will be passed to the given `formatFn`
7171
* and returned on the spot.
7272
*
73-
* @template TIn The type of values yielded by the passed iterable or of a plain value passed otherwise.
73+
* @template TIn The full type of the source input.
7474
* @template TRes The type of values resulting after formatting.
7575
*
7676
* @param source Any async iterable or plain value.
7777
* @param formatFn Function that performs formatting/mapping logic for each value of `source`
7878
*
7979
* @returns a transformed async iterable emitting every value of `source` after formatting.
8080
*/
81-
function iterateFormatted<TIn extends AsyncIterable<unknown>, TRes>(
81+
function iterateFormatted<TIn, TRes>(
8282
source: TIn,
8383
formatFn: (
8484
value: ExtractAsyncIterValue<TIn> | (TIn extends AsyncIterableSubject<infer J> ? J : never),
@@ -89,8 +89,6 @@ function iterateFormatted<TIn extends AsyncIterable<unknown>, TRes>(
8989
? { value: Required<AsyncIterableSubject<TRes>['value']> }
9090
: { value: undefined });
9191

92-
function iterateFormatted<TIn, TRes>(source: TIn, formatFn: (value: TIn, i: number) => TRes): TRes;
93-
9492
function iterateFormatted(
9593
source:
9694
| undefined

0 commit comments

Comments
 (0)