Crustack
@crustack/utils

types

👉 DistributiveOmit

Same as Omit, but works with unions.

import {  } from '@crustack/utils'

// works as expected:
// Omit<{ a: string, b: string }, "c"> | Omit<{ b: string, c: string }, "c">
type  = <
  { : string; : string } | { : string; : string },
  'c'
>

// forgets both 'a' and 'c':
// { b: string }
type  = <{ : string; : string } | { : string; : string }, 'c'>

👉 EntryOf

Transform an object type into a union of its entries.

import {  } from '@crustack/utils'

type  = {
  : number
  : string
}

type  = <>
// ['a', number] | ['b', string]

👉 KeyOf

Same as keyof, but works with unions.

import {  } from '@crustack/utils'

type  =
  | {
      : number
      : string
    }
  | {
      : string
      ?: boolean
    }

type  = <>
// 'a' | 'b' | 'c'

type  = keyof 
// 'b'

👉 MaybeArray

Describe a type that might be an Array

import {  } from '@crustack/utils'

type  = <{ : string }>
// T = { a: string } | Array<{ a: string }>

👉 MaybePromise

Describe a type that might be a Promise

import {  } from '@crustack/utils'

type  = <{ : string }>
// T = { a: string } | Promise<{ a: string }>

👉 Prettify

More readable types.

import {  } from '@crustack/utils'

type  = <>

👉 UnionToIntersection

Transform a Union type to an Intersection type.

import {  } from '@crustack/utils'

type  = <{ : string } | { : number }>
// I = { a: string } & { b: number }

👉 ValueOf

Extracts the value types of an object type.

Same as KeyOf, but for values.

import {  } from '@crustack/utils'

type  = {
  : number
  : string
}

type  = <>
// number | string

On this page