How to typecast the return value of the Thunk of action?

Hi.

The situation is this:

1) There is an asynchronous action
type AppThunk<ReturnType = void> = ThunkAction<
ReturnType,
RootState,
unknown,
Action<string>
>

export const registerUserAsync = (form: RegisterFormType): AppThunk<Promise<RegisterFormType>> => {
 return dispatch => new Promise(resolve => {
resolve(form);
})
};


2) A functional component
const dispatch = useDispatch();
const onRegister = async (newFormData: RegisterFormType) => {
 const form: RegisterFormType = await dispatch(registerAction.registerUserAsync(newFormData));
};


The problem is that const form: RegisterFormType is highlighted by TS and then not work, then there is exactly distpach returns a Promise, but TS doesn't know that pointing generic dispatch<Promise<RegisterFormType>> he begins to swear on the input parameter action registerAction.registerUserAsync

Please help me with correct typing
April 19th 20 at 12:38
0 answer

Find more questions by tags ReduxReactTypeScript