From 6f41e981d1f17a27eabf2b2ba953d1e41ef6fb62 Mon Sep 17 00:00:00 2001 From: Andy Wermke Date: Tue, 23 Jun 2020 17:00:01 +0200 Subject: [PATCH] Improve iterable detection Thanks, @kimamula! (See #256) --- src/serializers/iterators.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/serializers/iterators.ts b/src/serializers/iterators.ts index 510a8821..35279119 100644 --- a/src/serializers/iterators.ts +++ b/src/serializers/iterators.ts @@ -41,7 +41,10 @@ export const DefaultIteratorSerializer = (rootSerializer: Serializer): Serialize }) export const isIterator = (thing: any): thing is Iterator | AsyncIterator => - thing && typeof thing === "object" && "next" in thing && typeof thing.next === "function" + thing && typeof thing === "object" && ( + typeof thing.next === "function" || + typeof (thing as AsyncIterable)[Symbol.asyncIterator] === "function" + ) export const isSerializedIterator = (thing: any): thing is SerializedIterator => thing && typeof thing === "object" && "__iterator_marker" in thing && thing.__iterator_marker === "$$iterator"