Skip to content

Commit 18968f9

Browse files
committed
Improve iterable detection
Thanks, @kimamula! (See #256)
1 parent 67a09d4 commit 18968f9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: src/serializers/iterators.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export const DefaultIteratorSerializer = (rootSerializer: Serializer): Serialize
4141
})
4242

4343
export const isIterator = (thing: any): thing is Iterator<any> | AsyncIterator<any> =>
44-
thing && typeof thing === "object" && "next" in thing && typeof thing.next === "function"
44+
thing && typeof thing === "object" && (
45+
typeof thing.next === "function" ||
46+
typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] === "function"
47+
)
4548

4649
export const isSerializedIterator = (thing: any): thing is SerializedIterator =>
4750
thing && typeof thing === "object" && "__iterator_marker" in thing && thing.__iterator_marker === "$$iterator"

0 commit comments

Comments
 (0)