In order to streamline the process, I want to define the necessary properties in a single list[], and then use that as the template for both types I am utilizing. Currently, I have to manually input them in two separate locations.
By employing keyof
, I can ensure that I am only choosing from available props
type DealPropertiesKeys = keyof DealProperties
This enables me to specify which properties need to be retrieved from the API
const deal = await hubSpotClient.crm.deals.basicApi.getById(dealId, [
'dealname',
'loan_type',
'asset_type',
'a_c_square_footage',
'borrowing_entity_type',
'borrowing_entity',
'date_of_formation',
'estimated_value',
'exit_strategy',
'fixed_or_arm',
'intended_use',
'lender',
'loan_channel',
'loan_program',
'ltv',
'project_name',
'property_address',
'property_type',
'requested_terms',
'subject_property_address',
'subject_property_city',
'subject_property_state',
'subject_property_zip_code',
'year_built',
'amount',
'hubspot_owner_id',
'outstanding_mortgage_balance',
] as DealPropertiesKeys[])
When working with the returned object, I aim to type it according to the selected properties on the request.
type DealProps = Pick<
DealProperties,
| 'dealname'
| 'loan_type'
| 'asset_type'
| 'a_c_square_footage'
| 'borrowing_entity_type'
| 'borrowing_entity'
| 'date_of_formation'
| 'estimated_value'
| 'exit_strategy'
| 'fixed_or_arm'
| 'intended_use'
| 'lender'
| 'loan_channel'
| 'loan_program'
| 'ltv'
| 'project_name'
| 'property_address'
| 'property_type'
| 'requested_terms'
| 'subject_property_address'
| 'subject_property_city'
| 'subject_property_state'
| 'subject_property_zip_code'
| 'year_built'
| 'amount'
| 'hubspot_owner_id'
| 'outstanding_mortgage_balance'
>