1 | import { Middleware } from 'redux'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export type IsAny<T, True, False = never> =
|
10 |
|
11 | true | false extends (T extends never ? true : false) ? True : False
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export type IsUnknown<T, True, False = never> = unknown extends T
|
20 | ? IsAny<T, False, True>
|
21 | : False
|
22 |
|
23 | export type FallbackIfUnknown<T, Fallback> = IsUnknown<T, Fallback, T>
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export type IfMaybeUndefined<P, True, False> = [undefined] extends [P]
|
29 | ? True
|
30 | : False
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export type IfVoid<P, True, False> = [void] extends [P] ? True : False
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | export type IsEmptyObj<T, True, False = never> = T extends any
|
41 | ? keyof T extends never
|
42 | ? IsUnknown<T, False, IfMaybeUndefined<T, False, IfVoid<T, False, True>>>
|
43 | : False
|
44 | : never
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | export type AtLeastTS35<True, False> = [True, False][IsUnknown<
|
55 | ReturnType<<T>() => T>,
|
56 | 0,
|
57 | 1
|
58 | >]
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | export type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35<
|
64 | IsUnknown<T, True, False>,
|
65 | IsEmptyObj<T, True, IsUnknown<T, True, False>>
|
66 | >
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export type DispatchForMiddlewares<M> = M extends ReadonlyArray<any>
|
73 | ? UnionToIntersection<
|
74 | M[number] extends infer MiddlewareValues
|
75 | ? MiddlewareValues extends Middleware<infer DispatchExt, any, any>
|
76 | ? DispatchExt extends Function
|
77 | ? DispatchExt
|
78 | : never
|
79 | : never
|
80 | : never
|
81 | >
|
82 | : never
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export type UnionToIntersection<U> = (U extends any
|
88 | ? (k: U) => void
|
89 | : never) extends (k: infer I) => void
|
90 | ? I
|
91 | : never
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export type NoInfer<T> = [T][T extends any ? 0 : never]
|
101 |
|
102 | export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>
|
103 |
|
104 | export interface HasMatchFunction<T> {
|
105 | match(v: any): v is T
|
106 | }
|
107 |
|
108 | export const hasMatchFunction = <T>(
|
109 | v: Matcher<T>
|
110 | ): v is HasMatchFunction<T> => {
|
111 | return v && typeof (v as HasMatchFunction<T>).match === 'function'
|
112 | }
|
113 |
|
114 |
|
115 | export type Matcher<T> = HasMatchFunction<T> | ((v: any) => v is T)
|
116 |
|
117 | /** @public */
|
118 | export type ActionFromMatcher<M extends Matcher<any>> = M extends Matcher<
|
119 | infer T
|
120 | >
|
121 | ? T
|
122 | : never
|
123 |
|
\ | No newline at end of file |