Skip to content

Commit

Permalink
fix: unwrap promises for map if AsyncLazy (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler authored Mar 24, 2024
1 parent 75b4cd7 commit 485d1f4
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type FlatIterable<TIterable, TDepth extends number> = {
[-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20][TDepth]
>
: TIterable extends AsyncIterable<infer InnerItr>
? FlatIterable<
InnerItr,
// prettier-ignore
[-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20][TDepth]
>
: TIterable;
? FlatIterable<
InnerItr,
// prettier-ignore
[-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20][TDepth]
>
: TIterable;
}[TDepth extends -1 ? 'done' : 'recur'];

interface AsyncLazy<T> extends Lazy<T>, AsyncIterable<T> {
Expand All @@ -42,19 +42,15 @@ interface SyncLazy<T> extends Lazy<T>, Iterable<T> {
asyncIterable: undefined;
}

type InferLazyKind<
TClass extends Lazy<any>,
TValue,
> = TClass extends AsyncLazy<any>
? AsyncLazy<TValue>
: TClass extends SyncLazy<TValue>
? SyncLazy<TValue>
: Lazy<TValue>;

type ConditionalPromise<
TClass extends Lazy<any>,
TValue,
> = TClass extends AsyncLazy<any> ? Promise<TValue> : TValue;
type InferLazyKind<TClass extends Lazy<any>, TValue> =
TClass extends AsyncLazy<any>
? AsyncLazy<Awaited<TValue>>
: TClass extends SyncLazy<TValue>
? SyncLazy<TValue>
: Lazy<TValue>;

type ConditionalPromise<TClass extends Lazy<any>, TValue> =
TClass extends AsyncLazy<any> ? Promise<TValue> : TValue;

/**
* A small, _useful_ set of methods for lazy iteration of iterables
Expand Down

0 comments on commit 485d1f4

Please sign in to comment.