response
の存在を確認しないと、次のコードフローでエラーが発生します。しかし、const response
の定義では、応答が利用可能であることを保証する必要があります。なぜフローはresponse
の存在のチェックを省略することができないのですか?なぜ定義されている未定義の値がチェックされますか?
/* @flow */
// ... import dependencies
export function* loadDepartments(): Generator<*, *, *> {
try {
const response = yield call(getJson, endpoints.departments);
if (response && typeof response.data !== 'undefined') {
yield put(actions.loadingDepartmentsSucceeded(response.data));
}
} catch (errors) {
yield put(actions.loadingDepartmentsFailed(errors));
}
}
私は 'response.data'を途中で確認することができますが、そのプロパティが存在するという保証はありません。 – vkjb38sjhbv98h4jgvx98hah3fef