1.2.0 • Published 3 years ago

x-ts-utils v1.2.0

Weekly downloads
19
License
MIT
Repository
github
Last release
3 years ago

x-ts-utils

A modest little Typescript helper library. Currently, consists of 3 helper functions, a Result<Value, Error> type, and a ValuesOf<T> type, mostly for getting type-safety when doing functional things:

export function isDefined<T>(x: T | undefined): x is T {
  return typeof x !== `undefined`;
}

export function isNotNull<T>(x: T | null): x is T {
  return x !== null;
}

export function isNotFalse<T>(x: T | false): x is T {
  return x !== false;
}

export type Result<Value, Error = string> =
  | {
      success: true;
      value: Value;
    }
  | {
      success: false;
      error: Error;
    };

export type ValuesOf<T extends Record<string, unknown>> = T[keyof T];