import { NonNull, Optional } from './standard-types' import { Profile } from './enum-types' // ------------------------------------------------------------------------------------------------- /** * BufferEncoding * @desc Type representing supported buffer encoding settings */ export type BufferEncoding = | 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex' // ------------------------------------------------------------------------------------------------- /** * ProcessConfig * @desc Type representing supported process configurations */ export type ProcessConfig = { readonly env: T } export const dev: ProcessConfig = { env: Profile.dev } export const prod: ProcessConfig = { env: Profile.prod } export const test: ProcessConfig = { env: Profile.test } // ------------------------------------------------------------------------------------------------- /** * SearchOptions * @desc Type representing search options */ export type SearchOptions = { limit?: number suggest?: boolean where?: { [key: string]: string } field?: string | string[] bool?: 'and' | 'or' | 'not' } // ------------------------------------------------------------------------------------------------- /** * Keys * @desc Get the union type of all the keys in an object type `T` * @see https://flow.org/en/docs/types/utilities/#toc-keys * @example * type Props = { name: string; age: number; visible: boolean }; * * // Expect: "name" | "age" | "visible" * type PropsKeys = Keys; */ export type Keys = keyof T // ------------------------------------------------------------------------------------------------- /** * Values * @desc Get the union type of all the values in an object type `T` * @see https://flow.org/en/docs/types/utilities/#toc-values * @example * type Props = { name: string; age: number; visible: boolean }; * * // Expect: string | number | boolean * type PropsValues = Values; */ export type Values = T[keyof T] // ------------------------------------------------------------------------------------------------- /** * PropertyType * @desc Get the type of property of an object at a given key `K` * @see https://flow.org/en/docs/types/utilities/#toc-propertytype * @example * // Expect: string; * type Props = { name: string; age: number; visible: boolean }; * type NameType = PropertyType; * * // Expect: boolean * type Tuple = [boolean, number]; * type A = PropertyType; * // Expect: number * type B = PropertyType; */ export type PropertyType = T[K] // ------------------------------------------------------------------------------------------------- /** * ElementType * @desc Get the type of elements inside of array, tuple or object of type `T`, that matches the given index type `K` * @see https://flow.org/en/docs/types/utilities/#toc-elementtype * @example * // Expect: string; * type Props = { name: string; age: number; visible: boolean }; * type NameType = ElementType; * * // Expect: boolean * type Tuple = [boolean, number]; * type A = ElementType; * // Expect: number * type B = ElementType; * * // Expect: boolean * type Arr = boolean[]; * type ItemsType = ElementType; * * // Expect: number * type Obj = { [key: string]: number }; * type ValuesType = ElementType; */ export type ElementType = T[K] // ------------------------------------------------------------------------------------------------- /** * Shape * @desc Copies the shape of the type supplied, but marks every field optional. * @see https://flow.org/en/docs/types/utilities/#toc-shape * @example * type Props = { name: string; age: number; visible: boolean }; * * // Expect: Partial * type PartialProps = Shape; */ export type Shape = Partial // ------------------------------------------------------------------------------------------------- /** * Call * @desc Get the return type from a given typeof expression * @see https://flow.org/en/docs/types/utilities/#toc-call * @example * // Common use-case * const add = (amount: number) => ({ type: 'ADD' as 'ADD', payload: amount }); * type AddAction = Call; // { type: 'ADD'; payload: number } * * // Examples migrated from Flow docs * type ExtractPropType = (arg: T) => T['prop']; * type Obj = { prop: number }; * type PropType = Call>; // number * * type ExtractReturnType any> = (arg: T) => ReturnType; * type Fn = () => number; * type FnReturnType = Call>; // number */ export type Call any> = Fn extends (arg: any) => infer RT ? RT : never // ------------------------------------------------------------------------------------------------- /** * Class * @desc Represents constructor of type T * @see https://flow.org/en/docs/types/utilities/#toc-class * @example * class Store {} * function makeStore(storeClass: Class): Store { * return new storeClass(); * } */ export type Class = new (...args: any[]) => T // ------------------------------------------------------------------------------------------------- /** * mixed * @desc An arbitrary type that could be anything * @see https://flow.org/en/docs/types/mixed * @example * * function stringify(value: mixed) { * // ... * } * * stringify("foo"); * stringify(3.14); * stringify(null); * stringify({}); */ export type mixed = unknown // ------------------------------------------------------------------------------------------------- /** * Numeric * @desc Pair2 type with numeric ("number" | "bigint") value */ export type Numeric = number | bigint // ------------------------------------------------------------------------------------------------- /** * Pair2 * @desc Pair2 type with first and second values */ export type Tuple2 = { first: T; second: V } /** * Pair3 * @desc Pair3 type with first, second and third values */ export type Tuple3 = { first: T; second: V; third: R } /** * Pair4 * @desc Pair4 type with first, second, third and fourth values */ export type Tuple4 = { first: T; second: V; third: R; fourth: S } /** * Pair5 * @desc Pair5 type with first, second, third, fourth and fifth values */ export type Tuple5 = { first: T; second: V; third: R; fourth: S; fifth: M } /** * Pair6 * @desc Pair6 type with first, second, third, fourth, fifth and sixth values */ export type Tuple6 = { first: T; second: V; third: R; fourth: S; fifth: M; sixth: N } // ------------------------------------------------------------------------------------------------- /** * Pair * @desc Pair type with left and right values */ export type Pair = { left: T; right: V } /** * ReversePair * @desc Revers pair type with left and right values */ export type ReversePair = Pair /** * OptionalPair * @desc Optional pair type with left and right optional values */ export type OptionalPair = Pair, Optional> /** * PartialPair * @desc Partial pair type with left and right partial values */ export type PartialPair = Pair, Partial> /** * RequiredPair * @desc Required pair type with left and right required values */ export type RequiredPair = Pair, Required> /** * NonNullPair * @desc Non-nullable pair type with left and right non-nullable values */ export type NonNullPair = Pair, NonNull> /** * OptionalLeft * @desc Optional pair type with optional left value */ export type OptionalLeft = Pair, V> /** * OptionalRight * @desc Optional pair type with optional right value */ export type OptionalRight = Pair> /** * PropertyKeyPair * @desc Property key pair type with left and right property key values */ export type PropertyKeyPair = Pair /** * NumberPair * @desc Number pair type with left and right number values */ export type NumberPair = Pair /** * StringPair * @desc String pair type with left and right string values */ export type StringPair = Pair /** * BooleanPair * @desc Boolean pair type with left and right boolean values */ export type BooleanPair = Pair /** * StringRegexPair * @desc String regex pair type with string left and regex right values */ export type StringRegexPair = Pair /** * RegexStringPair * @desc Regex string pair type with regex left and string right values */ export type RegexStringPair = Pair // ------------------------------------------------------------------------------------------------- /** * KeyValue * @desc KeyValue type with key and value properties */ export type KeyValue = { key: T; value: V } /** * OptionalKeyValue * @desc KeyValue type with key and optional value properties */ export type OptionalKeyValue = KeyValue> /** * PartialKeyValue * @desc KeyValue type with key and partial value properties */ export type PartialKeyValue = KeyValue> /** * RequiredKeyValue * @desc KeyValue type with key and required value properties */ export type RequiredKeyValue = KeyValue> /** * NonNullKeyValue * @desc KeyValue type with key and non-nullable value properties */ export type NonNullKeyValue = KeyValue> // ------------------------------------------------------------------------------------------------- /** * NameValue * @desc NameValue type with {@link PropertyKey} name and {@link V} value properties */ export type NameValue = { name: T; value: V } /** * OptionalNameValue * @desc Optional name-value type with {@link PropertyKey} name and {@link Optional} value properties */ export type OptionalNameValue = NameValue> /** * PartialValue * @desc NameValue type with {@link PropertyKey} name and {@link Partial} value properties */ export type PartialValue = NameValue> /** * RequiredValue * @desc NameValue type with {@link PropertyKey} name and {@link Required} value properties */ export type RequiredValue = NameValue> /** * NonNullNameValue * @desc Non-nullable name-value type with {@link PropertyKey} name and {@link NonNull} value properties */ export type NonNullNameValue = NameValue> /** * NumberNameValue * @desc Number name-value type with {@link PropertyKey} name and {@link number} value properties */ export type NumberNameValue = NameValue /** * StringNameValue * @desc String name-value type with {@link PropertyKey} name and {@link string} value properties */ export type StringNameValue = NameValue /** * BooleanNameValue * @desc Boolean name-value type with {@link PropertyKey} name and {@link boolean} value properties */ export type BooleanNameValue = NameValue /** * RegexNameValue * @desc Regex name-value type with {@link PropertyKey} name and {@link RegExp} value properties */ export type RegexNameValue = NameValue // ------------------------------------------------------------------------------------------------- /** * RangeValue * @desc RangeValue type with {@link T} lower and {@link T} upper bound properties */ export type Range = { lower: T; upper: T } /** * OptionalRange * @desc OptionalRange type with optional lower and upper bound properties */ export type OptionalRange = Range> /** * PartialRange * @desc OptionalRange type with partial lower and upper bound properties */ export type PartialRange = Range> /** * RequiredRange * @desc OptionalRange type with required lower and upper bound properties */ export type RequiredRange = Range> /** * NonNullRange * @desc OptionalRange type with non-nullable lower and upper bound properties */ export type NonNullRange = Range> /** * NumberRange * @desc NumberRange type with number lower and upper bound properties */ export type NumberRange = Range /** * DateRange * @desc DateRange type with date lower and upper bound properties */ export type DateRange = Range // ------------------------------------------------------------------------------------------------- /** * KeywordData * @desc KeywordData type with double-sized string/number array values */ export type KeywordData = [T, Numeric] /** * KeywordDict * @desc KeywordDict record type with string keys and keyword data values */ export type KeywordDict = Record> // -------------------------------------------------------------------------------------------------