Our redux-saga generator has multiple yield statements that return different results. I am struggling with typing them correctly.
Here's an illustration:
const addBusiness = function* addBusiness(action: AddBusinessActionReturnType): Generator<
Promise<Business> | SelectEffect | PutEffect<{ payload?: ActionPayload<Array<Business>>; type: string }>,
void,
Business | BusinessesContainer
> {
const { url, showToast = true } = action.payload;
const businessDetails: Business = yield Network.get<Business>( // TypeScript error: Type 'Business | BusinessesContainer' is not assignable to type 'Business'.
`businesses?url=${url}`,
);
if (showToast) {
const getBusinessesFromState = (state: AppState) => ({
...state.business.businesses,
});
const businesses: BusinessesContainer = yield select(getBusinessesFromState); // TypeScript error: Type 'Business | BusinessesContainer' is not assignable to type 'BusinessesContainer'
onAddBusinessSuccessToast(businesses, businessDetails);
}
yield put({ // TypeScript error: Type 'SimpleEffect<"PUT", PutEffectDescriptor<{ type: string; payload: Business[]; }>>' is not assignable to type 'SelectEffect'
type: constants.SAVE_BUSINESS_REQUEST,
payload: [businessDetails],
});
The comments above indicate the TypeScript errors we are encountering. Any assistance would be greatly appreciated. Thank you