// Copied from https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-338650717 export type AnyJson = boolean | number | string | null | JsonArray | JsonMap; export type JsonMap = { [key: string]: AnyJson }; export type JsonArray = Array; export const checkIsString = getRefinement( (value: unknown): Nullable => (typeof value === 'string' ? value : null), ); /** * https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 */ export type OmitStrict = Omit; /** * Unlike TypeScript's `NonNullable`, this does _not_ include `undefined` */ export type Nullable = T | null; export const isDefined = (x: T | null | undefined): x is T => x !== null && x !== undefined; export type NonEmptyArray = [T, ...T[]]; type Refinement = (a: A) => a is B; export function getRefinement(getB: (a: A) => Nullable): Refinement { return (a: A): a is B => isDefined(getB(a)); } export const checkIsNonEmptyArray = (a: T[]): a is NonEmptyArray => a.length > 0;