You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typescript 4.5 has introduced the Awaited type, which recursively extracts the value inside a promise.
I wanted to contribute to this library, but I got confused about how to implement it since it calls itself:
typeAwaited<T>=Textendsnull|undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` modeTextendsobject&{then(onfulfilled: infer F): any} ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrappedFextends((value: infer V, ...args: any)=>any) ? // if the argument to `then` is callable, extracts the first argumentAwaited<V> : // recursively unwrap the valuenever : // the argument to `then` was not callableT;// non-object or non-thenable
I was able to downlevel it from:
exporttypeK<T>=Awaited<Promise<T>>;
to
exporttypeK<T>=Textendsnull|undefined ? T : Textendsobject&{then(onfulfilled: infer F): any;} ? Fextends((value: infer V, ...args: any)=>any) ? Awaited<V> : never : T;
As you can see, Awaited calls itself recursively. I tried to look for different similar types that call themselves recursively, but I found none.
I'll be happy to create a PR for this, but I'm not sure how to proceed from here.
Typescript 4.5 has introduced the Awaited type, which recursively extracts the value inside a promise.
I wanted to contribute to this library, but I got confused about how to implement it since it calls itself:
I was able to downlevel it from:
to
As you can see, Awaited calls itself recursively. I tried to look for different similar types that call themselves recursively, but I found none.
I'll be happy to create a PR for this, but I'm not sure how to proceed from here.
You can see here my current attempt.
The text was updated successfully, but these errors were encountered: