From 6a75e1c8c82a1625867ea69be3d0c55697448f4e Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Mon, 27 May 2024 11:00:40 +0200 Subject: [PATCH] Fix `createDataLoadingThunk` to allow actions without arguments (#30439) --- .../mastodon/store/typed_functions.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/app/javascript/mastodon/store/typed_functions.ts b/app/javascript/mastodon/store/typed_functions.ts index 0392f373c..dae37e622 100644 --- a/app/javascript/mastodon/store/typed_functions.ts +++ b/app/javascript/mastodon/store/typed_functions.ts @@ -89,21 +89,17 @@ type OnData = ( }, ) => ReturnedData | DiscardLoadData | Promise; +type ArgsType = Record | undefined; + // Overload when there is no `onData` method, the payload is the `onData` result -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, thunkOptions?: AppThunkOptions, ): ReturnType>; // Overload when the `onData` method returns discardLoadDataInPayload, then the payload is empty -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, onDataOrThunkOptions?: @@ -113,10 +109,7 @@ export function createDataLoadingThunk< ): ReturnType>; // Overload when the `onData` method returns nothing, then the mayload is the `onData` result -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, onDataOrThunkOptions?: AppThunkOptions | OnData, @@ -126,7 +119,7 @@ export function createDataLoadingThunk< // Overload when there is an `onData` method returning something export function createDataLoadingThunk< LoadDataResult, - Args extends Record, + Args extends ArgsType, Returned, >( name: string, @@ -162,7 +155,7 @@ export function createDataLoadingThunk< */ export function createDataLoadingThunk< LoadDataResult, - Args extends Record, + Args extends ArgsType, Returned, >( name: string,