Skip to content

Instantly share code, notes, and snippets.

@chranderson
Last active March 17, 2024 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chranderson/ed50f6044a3bb1804c92c0596a55fa07 to your computer and use it in GitHub Desktop.
Save chranderson/ed50f6044a3bb1804c92c0596a55fa07 to your computer and use it in GitHub Desktop.
Typescript Patterns
/** String literal union from Enum */
enum Status {
FAILED: 'fail',
PENDING: 'pending,
SUCCESS: 'success',
}
type StatusType = `${AccessPassVariant}`
// StatusType = 'fail' | 'pending' | 'success'
----------------------
/** String literal union from Enum keys */
enum Status {
FAILED: 'fail',
PENDING: 'pending,
SUCCESS: 'success',
}
type StatusKeyType = keyof typeof Status
// StatusKeyType = 'FAILED' | 'PENDING' | 'SUCCESS'
-----------------------
/** 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]
} & {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment