In the following code I expect the API payload to contain either a shareholderCompany or a shareholderExternalPerson and whichever one resolves as being true will trigger a function call as seen below. For some reason it seems to think in the child function that the shareholderCompany is undefined.
export const upsert = async(serviceData: any, companyShareholder: CompanyShareholdersDefinitionInterface, { transaction }: any) => {
const { shareholderCompany, shareholderExternalPerson } = companyShareholder;
if (shareholderCompany) {
return upsertCompanyShareholderCompany(serviceData, companyShareholder, { transaction });
}
if (shareholderExternalPerson) {
return upsertCompanyShareholderPerson(serviceData, companyShareholder, { transaction });
}
}
export const upsertCompanyShareholderCompany = async(serviceData: any, companyShareholder: CompanyShareholdersDefinitionInterface, { transaction }: any) => {
const { company_id, source, class: shareholderClass, shareholderCompany } = companyShareholder;
// Says that shareholderCompany might be undefined
These are the types:
export type CompanyShareholdersDefinitionInterface = CompanyShareholdersCompanyInterface | CompanyShareholdersExternalPersonInterface;
interface CompanyShareholdersCompanyInterface {
shareholderCompany: CompanyDefinitionInterface,
shareholderExternalPerson?: ExternalPersonDefinitionInterface
}
interface CompanyShareholdersExternalPersonInterface {
shareholderCompany?: CompanyDefinitionInterface,
shareholderExternalPerson: ExternalPersonDefinitionInterface
}
What am I missing here that's causing it to complain?