add generic typed matcher for ease of building off legacy actions

feat/typed-generic-matcher
ChaosExAnima 3 days ago
parent cc1e65dcec
commit 9f55d2f14e
No known key found for this signature in database
GPG Key ID: 8F2B333100FB6117

@ -1,6 +1,8 @@
import type {
Action,
ActionCreatorWithPreparedPayload,
GetThunkAPI,
UnknownAction,
} from '@reduxjs/toolkit';
import {
createAsyncThunk as rtkCreateAsyncThunk,
@ -310,3 +312,15 @@ export function createDataLoadingThunk<
},
);
}
/**
* Provides a type guard for legacy string actions.
* @param type The action type string.
* @example
* if (matchAppAction('my_action_type')(action)) {
* // action is now typed
* }
*/
export function matchAppAction<TAction extends Action>(type: TAction['type']) {
return (action: UnknownAction): action is TAction => action.type === type;
}

Loading…
Cancel
Save