UNPKG

2.97 kBTypeScriptView Raw
1import type { Middleware } from 'redux';
2/**
3 * return True if T is `any`, otherwise return False
4 * taken from https://github.com/joonhocho/tsdef
5 *
6 * @internal
7 */
8export declare type IsAny<T, True, False = never> = true | false extends (T extends never ? true : false) ? True : False;
9/**
10 * return True if T is `unknown`, otherwise return False
11 * taken from https://github.com/joonhocho/tsdef
12 *
13 * @internal
14 */
15export declare type IsUnknown<T, True, False = never> = unknown extends T ? IsAny<T, False, True> : False;
16export declare type FallbackIfUnknown<T, Fallback> = IsUnknown<T, Fallback, T>;
17/**
18 * @internal
19 */
20export declare type IfMaybeUndefined<P, True, False> = [undefined] extends [P] ? True : False;
21/**
22 * @internal
23 */
24export declare type IfVoid<P, True, False> = [void] extends [P] ? True : False;
25/**
26 * @internal
27 */
28export declare type IsEmptyObj<T, True, False = never> = T extends any ? keyof T extends never ? IsUnknown<T, False, IfMaybeUndefined<T, False, IfVoid<T, False, True>>> : False : never;
29/**
30 * returns True if TS version is above 3.5, False if below.
31 * uses feature detection to detect TS version >= 3.5
32 * * versions below 3.5 will return `{}` for unresolvable interference
33 * * versions above will return `unknown`
34 *
35 * @internal
36 */
37export declare type AtLeastTS35<True, False> = [True, False][IsUnknown<ReturnType<(<T>() => T)>, 0, 1>];
38/**
39 * @internal
40 */
41export declare type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35<IsUnknown<T, True, False>, IsEmptyObj<T, True, IsUnknown<T, True, False>>>;
42/**
43 * Combines all dispatch signatures of all middlewares in the array `M` into
44 * one intersected dispatch signature.
45 */
46export declare type DispatchForMiddlewares<M> = M extends ReadonlyArray<any> ? UnionToIntersection<M[number] extends infer MiddlewareValues ? MiddlewareValues extends Middleware<infer DispatchExt, any, any> ? DispatchExt extends Function ? IsAny<DispatchExt, never, DispatchExt> : never : never : never> : never;
47/**
48 * Convert a Union type `(A|B)` to an intersection type `(A&B)`
49 */
50export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
51/**
52 * Helper type. Passes T out again, but boxes it in a way that it cannot
53 * "widen" the type by accident if it is a generic that should be inferred
54 * from elsewhere.
55 *
56 * @internal
57 */
58export declare type NoInfer<T> = [T][T extends any ? 0 : never];
59export declare type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
60export interface HasMatchFunction<T> {
61 match: (v: any) => v is T;
62}
63export declare const hasMatchFunction: <T>(v: Matcher<T>) => v is HasMatchFunction<T>;
64/** @public */
65export declare type Matcher<T> = HasMatchFunction<T> | ((v: any) => v is T);
66/** @public */
67export declare type ActionFromMatcher<M extends Matcher<any>> = M extends Matcher<infer T> ? T : never;
68
\No newline at end of file