Skip to content

Make useAsyncIterState iterable's type more accurate #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/tests/useAsyncIterState.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('`useAsyncIterState` hook', () => {
const yieldPromise1 = iterator1.next();
const yieldPromise2 = iterator2.next();

await iterator1.return!();
await iterator1.return();

{
const promiseStates = await Promise.all(
Expand All @@ -51,7 +51,7 @@ describe('`useAsyncIterState` hook', () => {
]);
}

await iterator2.return!();
await iterator2.return();

{
const promiseStates = await Promise.all(
Expand Down
9 changes: 7 additions & 2 deletions src/useAsyncIterState/IterableChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ class IterableChannel<TVal> {
this.#nextIteration.resolve({ done: true, value: undefined });
}

iterable = {
iterable: {
[Symbol.asyncIterator](): {
next(): Promise<IteratorResult<TVal, void>>;
return(): Promise<IteratorReturnResult<void>>;
};
} = {
[Symbol.asyncIterator]: () => {
const whenIteratorClosed = promiseWithResolvers<IteratorReturnResult<undefined>>();

Expand All @@ -33,5 +38,5 @@ class IterableChannel<TVal> {
},
};
},
} satisfies AsyncIterable<TVal, void, void>;
};
}
2 changes: 1 addition & 1 deletion src/useAsyncIterState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ function useAsyncIterState<TVal>(): AsyncIterStateResult<TVal> {
*
* @see {@link useAsyncIterState `useAsyncIterState`}
*/
type AsyncIterStateResult<TVal> = [AsyncIterable<TVal, void, void>, (newValue: TVal) => void];
type AsyncIterStateResult<TVal> = [IterableChannel<TVal>['iterable'], (newValue: TVal) => void];
Loading