Take a look at the request methods' params in this class
export type SDKmodules = 'orders' |'pricing' |'catalogV2' |'catalog' |'prodType' |'reports' |'listings';
export class SellerAPI {
request(mod: SDKmodules, method: string, params: any = {}) {
return this.http.get<any>( `/sp-sdk/${mod}/${method}`, { params });
}
}
I am trying to type the request parameters based on the chosen module. Each module is a class. Here is a simplified down view.
{
orders: ['getOrder', 'getOrderExt', 'getOrderItems', 'saveOrders'],
pricing: ["getCompetitivePricing", "getItemOffers", "getListingOffers", "getPricing"],
catalogV2: ["getCatalogItem", "searchCatalogItems", "getCatalogProdType"],
}
so if the module choice was orders then the only acceptable method would be...
'getOrder', 'getOrderExt', 'getOrderItems', 'saveOrders'
Im looking for the most appropriate way to type this method. even if it means undoing any part of the sample code above.
Here are somethings i think might work.
- Multiple overloads for the request method
- Because all of the "modules" (the parameter) are class objects. Is there a way to use the modules them selves to type this method?
Im pretty new to typescript. Thank you in advance.