Fix createDataLoadingThunk
to allow actions without arguments (#30439)
This commit is contained in:
parent
a5c808e9b0
commit
6a75e1c8c8
1 changed files with 7 additions and 14 deletions
|
@ -89,21 +89,17 @@ type OnData<LoadDataResult, ReturnedData> = (
|
||||||
},
|
},
|
||||||
) => ReturnedData | DiscardLoadData | Promise<ReturnedData | DiscardLoadData>;
|
) => ReturnedData | DiscardLoadData | Promise<ReturnedData | DiscardLoadData>;
|
||||||
|
|
||||||
|
type ArgsType = Record<string, unknown> | undefined;
|
||||||
|
|
||||||
// Overload when there is no `onData` method, the payload is the `onData` result
|
// Overload when there is no `onData` method, the payload is the `onData` result
|
||||||
export function createDataLoadingThunk<
|
export function createDataLoadingThunk<LoadDataResult, Args extends ArgsType>(
|
||||||
LoadDataResult,
|
|
||||||
Args extends Record<string, unknown>,
|
|
||||||
>(
|
|
||||||
name: string,
|
name: string,
|
||||||
loadData: (args: Args) => Promise<LoadDataResult>,
|
loadData: (args: Args) => Promise<LoadDataResult>,
|
||||||
thunkOptions?: AppThunkOptions,
|
thunkOptions?: AppThunkOptions,
|
||||||
): ReturnType<typeof createThunk<Args, LoadDataResult>>;
|
): ReturnType<typeof createThunk<Args, LoadDataResult>>;
|
||||||
|
|
||||||
// Overload when the `onData` method returns discardLoadDataInPayload, then the payload is empty
|
// Overload when the `onData` method returns discardLoadDataInPayload, then the payload is empty
|
||||||
export function createDataLoadingThunk<
|
export function createDataLoadingThunk<LoadDataResult, Args extends ArgsType>(
|
||||||
LoadDataResult,
|
|
||||||
Args extends Record<string, unknown>,
|
|
||||||
>(
|
|
||||||
name: string,
|
name: string,
|
||||||
loadData: (args: Args) => Promise<LoadDataResult>,
|
loadData: (args: Args) => Promise<LoadDataResult>,
|
||||||
onDataOrThunkOptions?:
|
onDataOrThunkOptions?:
|
||||||
|
@ -113,10 +109,7 @@ export function createDataLoadingThunk<
|
||||||
): ReturnType<typeof createThunk<Args, void>>;
|
): ReturnType<typeof createThunk<Args, void>>;
|
||||||
|
|
||||||
// Overload when the `onData` method returns nothing, then the mayload is the `onData` result
|
// Overload when the `onData` method returns nothing, then the mayload is the `onData` result
|
||||||
export function createDataLoadingThunk<
|
export function createDataLoadingThunk<LoadDataResult, Args extends ArgsType>(
|
||||||
LoadDataResult,
|
|
||||||
Args extends Record<string, unknown>,
|
|
||||||
>(
|
|
||||||
name: string,
|
name: string,
|
||||||
loadData: (args: Args) => Promise<LoadDataResult>,
|
loadData: (args: Args) => Promise<LoadDataResult>,
|
||||||
onDataOrThunkOptions?: AppThunkOptions | OnData<LoadDataResult, void>,
|
onDataOrThunkOptions?: AppThunkOptions | OnData<LoadDataResult, void>,
|
||||||
|
@ -126,7 +119,7 @@ export function createDataLoadingThunk<
|
||||||
// Overload when there is an `onData` method returning something
|
// Overload when there is an `onData` method returning something
|
||||||
export function createDataLoadingThunk<
|
export function createDataLoadingThunk<
|
||||||
LoadDataResult,
|
LoadDataResult,
|
||||||
Args extends Record<string, unknown>,
|
Args extends ArgsType,
|
||||||
Returned,
|
Returned,
|
||||||
>(
|
>(
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -162,7 +155,7 @@ export function createDataLoadingThunk<
|
||||||
*/
|
*/
|
||||||
export function createDataLoadingThunk<
|
export function createDataLoadingThunk<
|
||||||
LoadDataResult,
|
LoadDataResult,
|
||||||
Args extends Record<string, unknown>,
|
Args extends ArgsType,
|
||||||
Returned,
|
Returned,
|
||||||
>(
|
>(
|
||||||
name: string,
|
name: string,
|
||||||
|
|
Loading…
Reference in a new issue