Skip to content

Instantly share code, notes, and snippets.

@keidarcy
Created September 26, 2021 08:43
Show Gist options
  • Save keidarcy/fa75c2e17bbeed2610baf22e568a1677 to your computer and use it in GitHub Desktop.
Save keidarcy/fa75c2e17bbeed2610baf22e568a1677 to your computer and use it in GitHub Desktop.
type helpers
export type Expect<T extends true> = T
export type ExpectTrue<T extends true> = T
export type ExpectFalse<T extends false> = T
export type IsTrue<T extends true> = T
export type IsFalse<T extends false> = T
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true
export type Equal<X, Y> =
(<T>() => T extends X ? 1 : 2) extends
(<T>() => T extends Y ? 1 : 2) ? true : false
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
export type IsAny<T> = 0 extends (1 & T) ? true : false
export type NotAny<T> = true extends IsAny<T> ? false : true
export type Debug<T> = { [K in keyof T]: T[K] }
export type MergeInsertions<T> =
T extends object
? { [K in keyof T]: MergeInsertions<T[K]> }
: T
export type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>
export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false
export type ExpectValidArgs<FUNC extends (...args: any[]) => any, ARGS extends any[]> = ARGS extends Parameters<FUNC>
? true
: false
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment