UNPKG

@mobily/ts-belt

Version:

🔧 Fast, modern, and practical utility library for FP in TypeScript.

55 lines (51 loc) • 1.47 kB
// @flow // see https://gist.github.com/thecotne/6e5969f4aaf8f253985ed36b30ac9fe0 type $FlowGen$If<X: boolean, Then, Else = empty> = $Call< ((true, Then, Else) => Then) & ((false, Then, Else) => Else), X, Then, Else >; type $FlowGen$Assignable<A, B> = $Call< ((...r: [B]) => true) & ((...r: [A]) => false), A >; export type Array<T> = $FlowGen$If< $FlowGen$Assignable<Belt.UseMutableArrays, 1>, T[], $ReadOnlyArray<T> >; export type Mutable<T> = $ObjMapi<T, <P>(P) => $ElementType<T, P>>; export type EmptyObject = { [key: string]: any, ... }; export type ExtractValue<T> = Exclude<T, null | void>; export type ExtractNested<T> = $FlowGen$If< $FlowGen$Assignable<T, Array<K>>, ExtractNested<K>, T >; export type GuardArray<T: mixed> = $FlowGen$If< $FlowGen$Assignable<Extract<T, Array<any>>, empty>, Array<mixed>, Extract<T, Array<any>> >; export type GuardPromise<T: mixed> = $FlowGen$If< $FlowGen$Assignable<Extract<T, Promise<any>>, empty>, Promise<mixed>, Extract<T, Promise<any>> >; export type GuardObject<T: mixed> = $FlowGen$If< $FlowGen$Assignable< Exclude<Extract<T, { [key: string]: any }>, Function | Array<any>>, empty >, { [k: string]: mixed, ... }, Exclude<Extract<T, { [key: string]: any }>, Function | Array<any>> >; export type GuardValue<T, V> = $FlowGen$If< $FlowGen$Assignable<Extract<T, V>, empty>, V, $FlowGen$If<$FlowGen$Assignable<Extract<T, V>, any>, V, Extract<T, V>> >;