From dba3d5f38b2b5eb14026a39e60703db962fe03a9 Mon Sep 17 00:00:00 2001 From: Dor Shtaif Date: Thu, 16 Jan 2025 15:44:18 +0200 Subject: [PATCH] fix `IterationResult` type's `pendingFirst` incorrectly inferred `false` instead of `boolean` when the source type is a regular async iter --- src/useAsyncIter/index.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/useAsyncIter/index.ts b/src/useAsyncIter/index.ts index e8229ee..5c4c608 100644 --- a/src/useAsyncIter/index.ts +++ b/src/useAsyncIter/index.ts @@ -119,10 +119,10 @@ const useAsyncIter: { value?: AsyncIterableSubject['value']; }, initialVal: MaybeFunction -): IterationResult => { +): IterationResult => { const rerender = useSimpleRerender(); - const stateRef = useRefWithInitialValue>(() => ({ + const stateRef = useRefWithInitialValue>(() => ({ value: callOrReturn(initialVal) /*as any*/, pendingFirst: true, done: false, @@ -259,11 +259,13 @@ type IterationResult = { } & ( | (TVal extends AsyncIterableSubject ? never - : { - pendingFirst: true; - done: false; - error: undefined; - }) + : TVal extends AsyncIterable + ? { + pendingFirst: true; + done: false; + error: undefined; + } + : never) | ({ pendingFirst: false; } & (