I'm currently working on a small project that involves creating lists of products in a certain format. For example:
let products = createList(
new Product('product1'),
new Product('product2')
)
When it comes to accessing a specific product, such as product1
, I typically use products.list['product1']
and then proceed with further actions. Each product within the list is designed with a name
property that corresponds to the first parameter passed in the constructor. Right now, products.list
utilizes a simple string index signature. What I really want to achieve is for intellisense to suggest properties like product1
, product2
, and so forth for the list
object. This functionality would be akin to how express handles request parameters:
https://i.stack.imgur.com/d0p4d.png
In my quest to address this issue, I delved into express' type declarations and extensively reviewed TypeScript documentation on utility types, particularly focusing on the Record type. Despite this effort, I still couldn't quite grasp the solution. It's possible that I may have been searching for the wrong information. Therefore, I would greatly appreciate any guidance in directing me towards the proper documentation.