Last active
July 26, 2024 20:10
-
-
Save chranderson/ed50f6044a3bb1804c92c0596a55fa07 to your computer and use it in GitHub Desktop.
Helpful Typescript Patterns
This file contains 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
/** TS inference helper | |
* Wrap an interface in Prettify to give you all of the properites you expect by hovering. | |
* Use to debug really complicated inheritance based inference | |
*/ | |
export type Prettify<T> = { | |
[K in keyof T]: T[K] | |
} & {} | |
---------------------- | |
/** String literal union from Enum */ | |
enum Status { | |
FAILED: 'failed', | |
PENDING: 'pending, | |
SUCCESS: 'success', | |
} | |
type StatusType = `${AccessPassVariant}` | |
// StatusType = 'failed' | 'pending' | 'success' | |
---------------------- | |
/** String literal union from Enum keys */ | |
enum Status { | |
FAILED: 'failed', | |
PENDING: 'pending, | |
SUCCESS: 'success', | |
} | |
type StatusKeyType = keyof typeof Status | |
// StatusKeyType = 'FAILED' | 'PENDING' | 'SUCCESS' | |
----------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment