From 060ea1aa34364e763a5d3ee476479450bb9f98d6 Mon Sep 17 00:00:00 2001 From: Dor Shtaif Date: Mon, 30 Dec 2024 20:43:51 +0200 Subject: [PATCH] add an exposed `MaybeAsyncIterable` helper generic type --- src/MaybeAsyncIterable/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/MaybeAsyncIterable/index.ts diff --git a/src/MaybeAsyncIterable/index.ts b/src/MaybeAsyncIterable/index.ts new file mode 100644 index 0000000..181f2c9 --- /dev/null +++ b/src/MaybeAsyncIterable/index.ts @@ -0,0 +1,26 @@ +export { MaybeAsyncIterable }; + +/** + * Helper type that represents either a plain value or an async iterable of that value. + * + * This type is useful among else for typing props for components that can accept either a + * _"static" value_ or a _"changing" value_ (an async iterable) seamlessly. + * + * @example + * ```tsx + * import { It, type MaybeAsyncIterable } from 'react-async-iterators'; + * + * function MyComponent(props: { values: MaybeAsyncIterable }) { + * return ( + * + * ); + * } + * ``` + */ +type MaybeAsyncIterable = T | AsyncIterable;