x-ts-utils

1.2.0 • Public • Published

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];

Readme

Keywords

none

Package Sidebar

Install

npm i x-ts-utils

Weekly Downloads

24

Version

1.2.0

License

MIT

Unpacked Size

2.57 kB

Total Files

6

Last publish

Collaborators

  • jaredhenderson