Redux saga, argument of type is not assignable to parameter of type

36 Views Asked by At

I am trying to get data from my api in my saga:

function* getVehicleReminderDatesAsync(
  action: types.GetVehicleReminderDatesAction,
) {
  const {
    payload: { registrations },
  } = action;
  
  try {
    const data: GetVehicleReminderDatesResult = yield call(() =>
      GetVehicleReminderDates(registrations),
    );

    if (data.responseCode === ResponseCode.SUCCESS) {
      // Typescript error on data.payload
      yield put(actions.GetVehicleReminderDatesSuccess(data.payload));
    }
  } catch (err) {
    ...
  }
}

actions.GetVehicleReminderDatesSuccess:

export const GetVehicleReminderDatesSuccess = (
  vehicles?: Array<{
    registration?: string;
    vehicleDetails?: {
      Make: string;
      Model: string;
      YearOfManufacture: string;
      Transmission: string;
      FuelType: string;
      MotExpiryDate: string;
      RegistrationDate: string;
      MotExpiryDateDescription: string;
      TaxDueDate: string;
      TaxDueDateDescription: string;
    };
  }>,
) => ({
  type: types.GET_VEHICLE_REMINDER_DATES_SUCCESS,
  payload: vehicles,
});

types.GetVehicleReminderDatesAction:

export interface GetVehicleReminderDatesAction {
  type: typeof GET_VEHICLE_REMINDER_DATES;
  payload: { registrations: Array<{ Registration: string }> | undefined };
}

VehicleReminderDatesResponse type:

  export type VehicleReminderDatesResponse = {
    registration?: string;
    vehicleDetails?: {
      FuelType?: string;
      Make?: string;
      Model?: string;
      MotExpiryDateDescription?: string;
      RegistrationDate?: string;
      TaxDueDate?: string;
      TaxDueDateDescription?: string;
      Transmission?: string;
      MotExpiryDate?: string;
      YearOfManufacture?: string;
    };
  };

Typescript error:

Argument of type 'VehicleReminderDatesResponse' is not assignable to parameter of type '{ registration?: string | undefined; vehicleDetails?: { Make: string; Model: string; YearOfManufacture: string; Transmission: string; FuelType: string; MotExpiryDate: string; RegistrationDate: string; MotExpiryDateDescription: string; TaxDueDate: string; TaxDueDateDescription: string; } | undefined; }[]'. Type 'VehicleReminderDatesResponse' is missing the following properties from type '{ registration?: string | undefined; vehicleDetails?: { Make: string; Model: string; YearOfManufacture: string; Transmission: string; FuelType: string; MotExpiryDate: string; RegistrationDate: string; MotExpiryDateDescription: string; TaxDueDate: string; TaxDueDateDescription: string; } | undefined; }[]': length, pop, push, concat, and 29 more.ts(2345)

0

There are 0 best solutions below