@@ -224,7 +224,7 @@ export type PayloadActionCreator<
224224 * A utility function to create an action creator for the given action type
225225 * string. The action creator accepts a single argument, which will be included
226226 * 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,
228228 * allowing it to be used in reducer logic that is looking for that action type.
229229 *
230230 * @param type The action type to use for created actions.
@@ -241,7 +241,7 @@ export function createAction<P = void, T extends string = string>(
241241 * A utility function to create an action creator for the given action type
242242 * string. The action creator accepts a single argument, which will be included
243243 * 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,
245245 * allowing it to be used in reducer logic that is looking for that action type.
246246 *
247247 * @param type The action type to use for created actions.
@@ -286,15 +286,25 @@ export function createAction(type: string, prepareAction?: Function): any {
286286 return actionCreator
287287}
288288
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+ */
289299export function isFSA ( action : unknown ) : action is {
290300 type : string
291301 payload ?: unknown
292302 error ?: unknown
293303 meta ?: unknown
294304} {
295305 return (
296- isPlainObject ( action ) &&
297- typeof ( action as any ) . type === 'string' &&
306+ isAction ( action ) &&
307+ typeof action . type === 'string' &&
298308 Object . keys ( action ) . every ( isValidKey )
299309 )
300310}
0 commit comments