I want to be able to define the properties I need in only 1 list[], and then use that as the definition for these 2 types I am using, right now I have to individually add them in both places.
Using keyof allows to make sure I am selecting from available props
type DealPropertiesKeys = keyof DealProperties
I can then define what properties should be fetched 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[])
Then when I need to use the returned object, I want to type it based on 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'
>