Created
June 3, 2021 17:53
-
-
Save windbridges/4ec21d6ded069a79d4b6cfb4ddde7ec4 to your computer and use it in GitHub Desktop.
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
| // Argument type based on value of another argument | |
| type OrderType = 'Simple' | 'Extended' | |
| interface OrderOptionsSet = { | |
| Simple: { | |
| name: string | |
| age: number | |
| }, | |
| Extended: { | |
| firstName: string | |
| lastName: string | |
| something: any | |
| } | |
| } | |
| async createTask<K extends OrderType>(type: K, options: OrderOptionsSet[K]): Promise<any> { | |
| // options type now will be OrderOptionsSet.Simple or OrderOptionsSet.Extended here bdepending on type value | |
| } | |
| // Return type based on return type of function, passed as argument | |
| export async function waitUntil<T>(fn: () => T, timeoutSec: number = 30): Promise<T> { | |
| // ... | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment