diff --git a/app/javascript/mastodon/store/typed_functions.ts b/app/javascript/mastodon/store/typed_functions.ts index 79bca08a52f..dec52771d98 100644 --- a/app/javascript/mastodon/store/typed_functions.ts +++ b/app/javascript/mastodon/store/typed_functions.ts @@ -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(type: TAction['type']) { + return (action: UnknownAction): action is TAction => action.type === type; +}