Skip to content

Instantly share code, notes, and snippets.

@huozhi
Last active January 16, 2023 17:37
Show Gist options
  • Save huozhi/5cd4697d9e46c3157430e63905056c14 to your computer and use it in GitHub Desktop.
Save huozhi/5cd4697d9e46c3157430e63905056c14 to your computer and use it in GitHub Desktop.
typescript cheat sheet
type KeysOfUnion<T> = T extends T ? keyof T : never
type Narrow<T> = T extends Function
? T
: never | T extends string | number | boolean | bigint
? T
: never | T extends []
? []
: never | { [K in keyof T]: Narrow<T[K]> }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment