I'm working on a small project that requires me to create lists of products more or less like so:
let products = createList(
new Product('product1'),
new Product('product2')
)
At some point I need to access some product - let's say it's the product1
. I'd do it like so - products.list['product1']
and then do some stuff with it. Each product in the list has a name
property that's derived from the first parameter in the constructor. At this moment products.list
is using a basic string index signature and what I'd like to acheve is so that intellisense could suggest that the list
object has properties product1
, product2
and so on. Similarly to how request parameters in express are done:
I inspected express' type declarations, read the TS docs on utility types, especially on the Record type as it seemed it was what I've been looking for but couldn't figure out what to do after all.
It's not impossible that I just searched for the wrong stuff. I'd really appreciate if somebody pointed me to the right docs.