I have two similar components that share most of the type and are pulled from look up table.
export type CrmValidationTableProps = {
orgId: string,
crmProjectId: number,
surveyId: string,
} & ({
crmSystem: 'airtable'
refinedData: AirtableExportRow[],
editQuestionIdentifierHandler: (row: AirtableExportRow) => void
} | {
crmSystem: 'salesforce'
refinedData: SalesforceExportRow[],
editQuestionIdentifierHandler: (row: SalesforceExportRow) => void
})
export function getCrmTables<T extends CrmValidationTableProps>(props: T): Record<crmSystem, React.ReactNode> {
return {
'salesforce': <SalesforceValidationTable {...props as T} />,
'airtable': <AirtableValidationTable {...props as T} />,
}
}
Now I use CrmValidationTableProps inside these react components too, I wonder how I can narrow them to their corresponding type, preferably using crmSystem