Fundamental
  • What is Fundamental?
  • Function
    • once
    • chain
  • Object
    • keys(), values(), entries()
    • hasOwn()
  • guards
    • Object.prototype.toString()
    • Primitive, object
    • Nullish(Nil)
    • Falsy, Truthy
  • Array
    • includes
    • shuffle
    • countBy
    • groupBy
  • misc
    • assert (invariant)
    • predicates
    • URL(SearchParams), encodeURI(Component)
    • to
  • types
    • UnionToIntersection
  • hooks
    • useCallbackRef
    • useIsomorphicLayoutEffect
    • useEvent
    • useHydrated
    • useControllableState
    • useList
    • useCheckList
  • react utils
    • mergeRefs
    • mergeProps
Powered by GitBook
On this page
  1. guards

Falsy, Truthy

type Falsy =
  | false
  | ""
  | 0
  | -0
  | 0n
  | -0n
  | null
  | undefined
  | void;

function isFalsy(value: unknown): value is Falsy {
  return !value;
}

type Truthy<T> = Exclude<T, Falsy>;

function isTruthy<T>(value: T): value is Truthy<T> {
  return !!value;
}

참고 자료

  • https://www.lucaspaganini.com/academy/custom-type-guards-typescript-narrowing-3

  • https://github.com/piotrwitek/utility-types/blob/master/src/aliases-and-guards.ts

PreviousNullish(Nil)Nextincludes

Last updated 2 years ago