My query resembles the one found in this Typescript interface definition question, but has a slight variation.
I am beginning with an object where the keys are constants:
const KEYS = {
KEY1: 'hello',
KEY2: 'world'
} as const;
However, instead of strings, I am using objects as the values. So, I am trying to determine the type of the object within each key. (All object types are the same.) For instance, I would like something along these lines:
const KEYS : {const: string} {
KEY1: 'hello',
KEY2: 'world'
} as const;
Is there a way to achieve this? I keep encountering ts2353 error due to the improper appearance of the const keyword. Ideally, I am looking for a one-line solution (i.e., what should replace const: string
to make it work) since I have nearly 200 keys and rewriting each const individually as a type is not preferable.
As per jcalz's suggestion, it seems like I need something akin to an "index signature"? I have experimented with various types but have not been able to find a working solution, so I am unsure about my approach.