I have a function that validates data for Kushki forms
export const validateKushkiForm = (type: KUSHKI_METHODS, kushkiData: KushkiCashType |
KushkiTransferType)
=> {
const errors = [];
if (type === KUSHKI_METHODS.CASH) {
!kushkiData.firstName && errors.push('firstName');
!kushkiData.lastName && errors.push('lastName');
!kushkiData.documentNumber && errors.push('documentNumber');
} else if (type === KUSHKI_METHODS.TRANSFER) {
!kushkiData.documentNumber && errors.push('documentNumber');
}
return errors;
};
For the type KushkiCashType, the properties include:
firstName: string;
lastName: string;
documentNumber: string;
For the type KushkiTransferType, it only has the property:
documentNumber: string;
Error message: 'Property 'firstName' does not exist on type 'KushkiCashType | KushkiTransferType'.
Property 'firstName' does not exist on type 'KushkiTransferType'.ts(2339)'
The issue arises because kushkiData can be of type KushkiCashType or KushkiTransferType. How can this error be resolved?