redux-saga-test-plan
redux-saga-test-plan copied to clipboard
Errors with TypeScript 3.7.2
After upgrading to TS 3.7.2, I started to get the following error types (for all of them I assume that TS before the update couldn't properly check the functions which now throw errors):
-
return expectSaga(watchForPostRequests)
- TS complains thatwatchForPostRequests
is not assignable toexpectSaga
since it expects anIterableIterator
and I'm passing in aGenerator
. The reason this is a bug is because the examples in the documentation are examples of aGenerator
- I assume before this update -
.then(result => {
- TS complains thatresult
implicitly hasany
type - it should beRunResult
-
.provide({ take(effect, next) {
- TS complains thateffect
andnext
implicitly haveany
type - these should beeffect: E.TakeEffectDescriptor & E.ChannelTakeEffectDescriptor<any>
andnext: ProviderNextF
Just realised only sometimes I get incorrect typings, so since the code is working 😁 I assume typings are incorrect. Points two and three happen in any place, point one happens when functions are declared in a certain way:
export function* watchAppStateChange() {
const stateChannel: Channel<AppStateType> = yield call(appStateChannel);
const appsFlyerDisableInstallEventsListener = appsFlyer.onInstallConversionData((data: any) => {
put(actionTrackAppsFlyerInstallConversion(data));
});
const appsFlyerDisableAtributionEventsListener = appsFlyer.onAppOpenAttribution((data: any) => {
put(actionTrackAppsFlyerOpenAttribution(data));
});
while (true) {
const state: AppStateType = yield take(stateChannel);
switch (state) {
case "active":
if (Platform.OS === "ios") {
appsFlyer.trackAppLaunch();
}
yield put(appStateChangedAction(state));
break;
case "inactive":
case "background":
yield put(appStateChangedAction(state));
if (appsFlyerDisableInstallEventsListener) {
appsFlyerDisableInstallEventsListener();
}
if (appsFlyerDisableAtributionEventsListener) {
appsFlyerDisableAtributionEventsListener();
}
break;
default:
throw new Error("assertState - invalid type");
}
}
}
export function* exerciseUpdater() {
while (true) {
yield take((action: ReduxAction) => actionShouldTriggerExerciseUpdate(action));
const exercisesFromDb: IExerciseReduxModel = yield select(getExercises);
const exercisesFromDbAreValid = exerciseModelIsValid(exercisesFromDb);
if (!exercisesFromDbAreValid) {
const exercisesFromDisk = yield call(loadExercisesFromDisk);
const exercisesFromDiskAreValid = exerciseModelIsValid(exercisesFromDisk);
if (exercisesFromDiskAreValid) {
yield put(exercisesLoadSuccessAction(exercisesFromDisk));
}
}
const lastTimeExercisesUpdated = yield select(getExercisesLastTimeUpdated);
yield put(getExercisesFromServerAction(lastTimeExercisesUpdated));
}
}
export function* serverPingerWatcher() {
while (true) {
yield take(OFFLINE);
const serverPingerTask: Task = yield call(serverPinger);
yield take(ONLINE);
if (serverPingerTask && serverPingerTask.isRunning()) {
serverPingerTask.cancel();
}
}
}
export function* doGenerateElapsedTimeEvents(generateElapsedTime: () => number) {
const elapsedTimeChannel: Channel<number> = yield call(timerChannel, generateElapsedTime);
while (true) {
try {
const elapsedTime = yield take(elapsedTimeChannel);
yield put(timeElapsed(elapsedTime));
} finally {
if (yield cancelled()) {
elapsedTimeChannel.close();
}
}
}
}