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