common.d.ts 817 B

123456789101112131415161718192021
  1. export type Data = { [key: string]: unknown }
  2. export type UnionToIntersection<U> = (
  3. U extends any ? (k: U) => void : never
  4. ) extends (k: infer I) => void
  5. ? I
  6. : never
  7. // Conditional returns can enforce identical types.
  8. // See here: https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
  9. // prettier-ignore
  10. type Equal<Left, Right> =
  11. (<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;
  12. export type HasDefined<T> = Equal<T, unknown> extends true ? false : true
  13. // If the type T accepts type "any", output type Y, otherwise output type N.
  14. // https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
  15. export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
  16. export type LooseRequired<T> = { [P in string & keyof T]: T[P] }