import type { Middleware } from 'redux' /** * return True if T is `any`, otherwise return False * taken from https://github.com/joonhocho/tsdef * * @internal */ export type IsAny = // test if we are going the left AND right path in the condition true | false extends (T extends never ? true : false) ? True : False /** * return True if T is `unknown`, otherwise return False * taken from https://github.com/joonhocho/tsdef * * @internal */ export type IsUnknown = unknown extends T ? IsAny : False export type FallbackIfUnknown = IsUnknown /** * @internal */ export type IfMaybeUndefined = [undefined] extends [P] ? True : False /** * @internal */ export type IfVoid = [void] extends [P] ? True : False /** * @internal */ export type IsEmptyObj = T extends any ? keyof T extends never ? IsUnknown>> : False : never /** * returns True if TS version is above 3.5, False if below. * uses feature detection to detect TS version >= 3.5 * * versions below 3.5 will return `{}` for unresolvable interference * * versions above will return `unknown` * * @internal */ export type AtLeastTS35 = [True, False][IsUnknown< ReturnType<() => T>, 0, 1 >] /** * @internal */ export type IsUnknownOrNonInferrable = AtLeastTS35< IsUnknown, IsEmptyObj> > /** * Combines all dispatch signatures of all middlewares in the array `M` into * one intersected dispatch signature. */ export type DispatchForMiddlewares = M extends ReadonlyArray ? UnionToIntersection< M[number] extends infer MiddlewareValues ? MiddlewareValues extends Middleware ? DispatchExt extends Function ? IsAny : never : never : never > : never /** * Convert a Union type `(A|B)` to an intersection type `(A&B)` */ export type UnionToIntersection = ( U extends any ? (k: U) => void : never ) extends (k: infer I) => void ? I : never /** * Helper type. Passes T out again, but boxes it in a way that it cannot * "widen" the type by accident if it is a generic that should be inferred * from elsewhere. * * @internal */ export type NoInfer = [T][T extends any ? 0 : never] export type Omit = Pick> export interface HasMatchFunction { match: (v: any) => v is T } export const hasMatchFunction = ( v: Matcher ): v is HasMatchFunction => { return v && typeof (v as HasMatchFunction).match === 'function' } /** @public */ export type Matcher = HasMatchFunction | ((v: any) => v is T) /** @public */ export type ActionFromMatcher> = M extends Matcher< infer T > ? T : never