1
- export interface FluxStandardAction < Payload , Meta = undefined > {
1
+ /**
2
+ * A Flux Standard action with optional payload and metadata properties.
3
+ */
4
+ export interface FluxStandardAction <
5
+ Type extends string = string ,
6
+ Payload = undefined ,
7
+ Meta = undefined
8
+ > {
2
9
/**
3
10
* The `type` of an action identifies to the consumer the nature of the action that has occurred.
4
11
* Two actions with the same `type` MUST be strictly equivalent (using `===`)
5
12
*/
6
- type : string ;
13
+ type : Type ;
7
14
/**
8
15
* The optional `payload` property MAY be any type of value.
9
16
* It represents the payload of the action.
@@ -26,36 +33,222 @@ export interface FluxStandardAction<Payload, Meta = undefined> {
26
33
meta ?: Meta ;
27
34
}
28
35
36
+ /**
37
+ * An extension of the Flux Standard action that represents an action containing an error as its payload.
38
+ */
29
39
export interface ErrorFluxStandardAction <
30
- CustomError extends Error ,
40
+ Type extends string = string ,
41
+ CustomError extends Error = Error ,
31
42
Meta = undefined
32
- > extends FluxStandardAction < CustomError , Meta > {
43
+ > extends FluxStandardAction < Type , CustomError , Meta > {
44
+ /**
45
+ * The required `error` property MUST be set to `true` if the action represents an error.
46
+ */
33
47
error : true ;
34
48
}
35
49
36
50
/**
37
51
* Alias for FluxStandardAction.
38
52
*/
39
- export type FSA < Payload , Meta = undefined > = FluxStandardAction < Payload , Meta > ;
53
+ export type FSA <
54
+ Type extends string = string ,
55
+ Payload = undefined ,
56
+ Meta = undefined
57
+ > = FluxStandardAction < Type , Payload , Meta > ;
40
58
41
59
/**
42
60
* Alias for ErrorFluxStandardAction.
43
61
*/
44
62
export type ErrorFSA <
45
- CustomError extends Error ,
46
- Meta = undefined
47
- > = ErrorFluxStandardAction < CustomError , Meta > ;
63
+ CustomError extends Error = Error ,
64
+ Meta = undefined ,
65
+ Type extends string = string
66
+ > = ErrorFluxStandardAction < Type , CustomError , Meta > ;
48
67
49
68
/**
50
69
* Returns `true` if `action` is FSA compliant.
51
70
*/
52
- export function isFSA < Payload , Meta = undefined > (
53
- action : any
54
- ) : action is FluxStandardAction < Payload , Meta > ;
71
+ export function isFSA <
72
+ Type extends string = string ,
73
+ Payload = undefined ,
74
+ Meta = undefined
75
+ > ( action : any ) : action is FluxStandardAction < Type , Payload , Meta > ;
55
76
56
77
/**
57
78
* Returns `true` if `action` is FSA compliant error.
58
79
*/
59
- export function isError < CustomError extends Error , Meta = undefined > (
60
- action : any
61
- ) : action is ErrorFluxStandardAction < CustomError , Meta > ;
80
+ export function isError <
81
+ Type extends string = string ,
82
+ CustomError extends Error = Error ,
83
+ Meta = undefined
84
+ > ( action : any ) : action is ErrorFluxStandardAction < Type , CustomError , Meta > ;
85
+
86
+ /**
87
+ * A Flux Standard action with a required payload property.
88
+ */
89
+ export interface FluxStandardActionWithPayload <
90
+ Type extends string = string ,
91
+ Payload = undefined ,
92
+ Meta = undefined
93
+ > extends FluxStandardAction < Type , Payload , Meta > {
94
+ /**
95
+ * The required `payload` property MAY be any type of value.
96
+ * It represents the payload of the action.
97
+ * Any information about the action that is not the type or status of the action should be part of the `payload` field.
98
+ * By convention, if `error` is `true`, the `payload` SHOULD be an error object.
99
+ * This is akin to rejecting a promise with an error object.
100
+ */
101
+ payload : Payload ;
102
+ }
103
+ /**
104
+ * Alias for FSAWithPayload
105
+ */
106
+ export type FSAWithPayload <
107
+ Type extends string = string ,
108
+ Payload = undefined ,
109
+ Meta = undefined
110
+ > = FluxStandardActionWithPayload < Type , Payload , Meta > ;
111
+
112
+ /**
113
+ * A Flux Standard action with a required metadata property.
114
+ */
115
+ export interface FluxStandardActionWithMeta <
116
+ Type extends string = string ,
117
+ Payload = undefined ,
118
+ Meta = undefined
119
+ > extends FluxStandardAction < Type , Payload , Meta > {
120
+ /**
121
+ * The required `meta` property MAY be any type of value.
122
+ * It is intended for any extra information that is not part of the payload.
123
+ */
124
+ meta : Meta ;
125
+ }
126
+ /**
127
+ * Alias for FluxStandardActionWithMeta
128
+ */
129
+ export type FSAWithMeta <
130
+ Type extends string = string ,
131
+ Payload = undefined ,
132
+ Meta = undefined
133
+ > = FluxStandardActionWithMeta < Type , Payload , Meta > ;
134
+
135
+ /**
136
+ * A Flux Standard action with required payload and metadata properties.
137
+ */
138
+ export type FluxStandardActionWithPayloadAndMeta <
139
+ Type extends string = string ,
140
+ Payload = undefined ,
141
+ Meta = undefined
142
+ > = FluxStandardActionWithPayload < Type , Payload , Meta > &
143
+ FluxStandardActionWithMeta < Type , Payload , Meta > ;
144
+ /**
145
+ * Alias for FluxStandardActionWithPayloadAndMeta
146
+ */
147
+ export type FSAWithPayloadAndMeta <
148
+ Type extends string = string ,
149
+ Payload = undefined ,
150
+ Meta = undefined
151
+ > = FluxStandardActionWithPayloadAndMeta < Type , Payload , Meta > ;
152
+
153
+ /**
154
+ * A Flux Standard action with inferred requirements for the payload and metadata properties.
155
+ * The `payload` and `meta` properties will be required if the corresponding type argument
156
+ * if not the `undefined` type.
157
+ */
158
+ export type FluxStandardActionAuto <
159
+ Type extends string = string ,
160
+ Payload = undefined ,
161
+ Meta = undefined
162
+ > = Payload extends undefined
163
+ ? ( Meta extends undefined
164
+ ? FluxStandardAction < Type , Payload , Meta >
165
+ : FluxStandardActionWithMeta < Type , Payload , Meta > )
166
+ : ( Meta extends undefined
167
+ ? FluxStandardActionWithPayload < Type , Payload , Meta >
168
+ : FluxStandardActionWithPayloadAndMeta < Type , Payload , Meta > ) ;
169
+ /**
170
+ * Alias for FluxStandardActionAuto
171
+ */
172
+ export type FSAAuto <
173
+ Type extends string = string ,
174
+ Payload = undefined ,
175
+ Meta = undefined
176
+ > = FluxStandardActionAuto < Type , Payload , Meta > ;
177
+
178
+ /**
179
+ * A Flux Standard Error Action with a required payload property.
180
+ */
181
+ export type ErrorFluxStandardActionWithPayload <
182
+ Type extends string = string ,
183
+ CustomError extends Error = Error ,
184
+ Meta = undefined
185
+ > = ErrorFluxStandardAction < Type , CustomError , Meta > &
186
+ FluxStandardActionWithPayload < Type , CustomError , Meta > ;
187
+ /**
188
+ * Alias for ErrorFluxStandardActionWithPayload
189
+ */
190
+ export type ErrorFSAWithPayload <
191
+ Type extends string = string ,
192
+ CustomError extends Error = Error ,
193
+ Meta = undefined
194
+ > = ErrorFluxStandardActionWithPayload < Type , CustomError , Meta > ;
195
+
196
+ /**
197
+ * A Flux Standard Error Action with a required metadata property.
198
+ */
199
+ export type ErrorFluxStandardActionWithMeta <
200
+ Type extends string = string ,
201
+ CustomError extends Error = Error ,
202
+ Meta = undefined
203
+ > = ErrorFluxStandardAction < Type , CustomError , Meta > &
204
+ FluxStandardActionWithMeta < Type , CustomError , Meta > ;
205
+ /**
206
+ * Alias for ErrorFluxStandardActionWithMeta
207
+ */
208
+ export type ErrorFSAWithMeta <
209
+ Type extends string = string ,
210
+ CustomError extends Error = Error ,
211
+ Meta = undefined
212
+ > = ErrorFluxStandardActionWithMeta < Type , CustomError , Meta > ;
213
+
214
+ /**
215
+ * A Flux Standard Error Action with required payload and metadata properties.
216
+ */
217
+ export type ErrorFluxStandardActionWithPayloadAndMeta <
218
+ Type extends string = string ,
219
+ CustomError extends Error = Error ,
220
+ Meta = undefined
221
+ > = ErrorFluxStandardActionWithPayload < Type , CustomError , Meta > &
222
+ ErrorFluxStandardActionWithMeta < Type , CustomError , Meta > ;
223
+ /**
224
+ * Alias for ErrorFluxStandardActionWithPayloadAndMeta
225
+ */
226
+ export type ErrorFSAWithPayloadAndMeta <
227
+ Type extends string = string ,
228
+ CustomError extends Error = Error ,
229
+ Meta = undefined
230
+ > = ErrorFluxStandardActionWithPayloadAndMeta < Type , CustomError , Meta > ;
231
+
232
+ /**
233
+ * A Flux Standard Error action with inferred requirements for the payload and metadata properties.
234
+ * The `payload` and `meta` properties will be required if the corresponding type argument
235
+ * if not the `undefined` type.
236
+ *
237
+ * Note: The `payload` property will always be required, since the `CustomError` type argument does
238
+ * not allow for specification of the `undefined` type.
239
+ */
240
+ export type ErrorFluxStandardActionAuto <
241
+ Type extends string = string ,
242
+ CustomError extends Error = Error ,
243
+ Meta = undefined
244
+ > = Meta extends undefined
245
+ ? ErrorFluxStandardActionWithPayload < Type , CustomError , Meta >
246
+ : ErrorFluxStandardActionWithPayloadAndMeta < Type , CustomError , Meta > ;
247
+ /**
248
+ * Alias for ErrorFluxStandardActionAuto
249
+ */
250
+ export type ErrorFSAAuto <
251
+ Type extends string = string ,
252
+ CustomError extends Error = Error ,
253
+ Meta = undefined
254
+ > = ErrorFluxStandardActionAuto < Type , CustomError , Meta > ;
0 commit comments