From 9f55d2f14eb3953bbffaea1f5aeeb4ac2f1f0cb3 Mon Sep 17 00:00:00 2001 From: ChaosExAnima Date: Fri, 20 Feb 2026 13:14:59 +0100 Subject: [PATCH] add generic typed matcher for ease of building off legacy actions --- app/javascript/mastodon/store/typed_functions.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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; +}