Skip to content

Instantly share code, notes, and snippets.

@dested
Created April 17, 2020 02:26
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 dested/c48f7256afa5aa6e251d6d9ee9286f19 to your computer and use it in GitHub Desktop.
Save dested/c48f7256afa5aa6e251d6d9ee9286f19 to your computer and use it in GitHub Desktop.
export type Discriminate<T, TField extends keyof T, TValue extends T[TField]> = T extends {[field in TField]: TValue}
? T
: never;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type IsUnion<T, U extends T = T> = T extends unknown ? ([U] extends [T] ? false : true) : false;
type IsStringUnion<T> = IsUnion<T> extends true ? (T extends string ? true : false) : false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment