@@ -224,7 +224,7 @@ export type PayloadActionCreator<
224
224
* A utility function to create an action creator for the given action type
225
225
* string. The action creator accepts a single argument, which will be included
226
226
* in the action object as a field called payload. The action creator function
227
- * will also have its toString() overriden so that it returns the action type,
227
+ * will also have its toString() overridden so that it returns the action type,
228
228
* allowing it to be used in reducer logic that is looking for that action type.
229
229
*
230
230
* @param type The action type to use for created actions.
@@ -241,7 +241,7 @@ export function createAction<P = void, T extends string = string>(
241
241
* A utility function to create an action creator for the given action type
242
242
* string. The action creator accepts a single argument, which will be included
243
243
* in the action object as a field called payload. The action creator function
244
- * will also have its toString() overriden so that it returns the action type,
244
+ * will also have its toString() overridden so that it returns the action type,
245
245
* allowing it to be used in reducer logic that is looking for that action type.
246
246
*
247
247
* @param type The action type to use for created actions.
@@ -286,15 +286,25 @@ export function createAction(type: string, prepareAction?: Function): any {
286
286
return actionCreator
287
287
}
288
288
289
+ /**
290
+ * Returns true if value is a plain object with a `type` property.
291
+ */
292
+ export function isAction ( action : unknown ) : action is Action < unknown > {
293
+ return isPlainObject ( action ) && 'type' in action
294
+ }
295
+
296
+ /**
297
+ * Returns true if value is an action with a string type and valid Flux Standard Action keys.
298
+ */
289
299
export function isFSA ( action : unknown ) : action is {
290
300
type : string
291
301
payload ?: unknown
292
302
error ?: unknown
293
303
meta ?: unknown
294
304
} {
295
305
return (
296
- isPlainObject ( action ) &&
297
- typeof ( action as any ) . type === 'string' &&
306
+ isAction ( action ) &&
307
+ typeof action . type === 'string' &&
298
308
Object . keys ( action ) . every ( isValidKey )
299
309
)
300
310
}
0 commit comments