Created
November 30, 2025 00:40
-
-
Save anztrax/ec404a64446b46d8cca447b7f7eedcdd to your computer and use it in GitHub Desktop.
Simple implementation of Awaited in Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type MyAwaited<T> = T extends PromiseLike<infer A> ? MyAwaited<A> : T; | |
| /* _____________ Test Cases _____________ */ | |
| import type { Equal, Expect } from '@type-challenges/utils' | |
| type X = Promise<string> | |
| type Y = Promise<{ field: number }> | |
| type Z = Promise<Promise<string | number>> | |
| type Z1 = Promise<Promise<Promise<string | boolean>>> | |
| type T = { then: (onfulfilled: (arg: number) => any) => any } | |
| type cases = [ | |
| Expect<Equal<MyAwaited<X>, string>>, | |
| Expect<Equal<MyAwaited<Y>, { field: number }>>, | |
| Expect<Equal<MyAwaited<Z>, string | number>>, | |
| Expect<Equal<MyAwaited<Z1>, string | boolean>>, | |
| Expect<Equal<MyAwaited<T>, number>>, | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment