I am exploring the concept of defining a Map type in Typescript using generics. Essentially, I want to create something similar to:
EntityMap<U, V>, where U can only be either a string or a number
This is what I have managed to come up with so far:
export type EntityMapKey = string | number;
export type EntityMap<U, V> = { [K in EntityMapKey]: V};
However, the issue arises when this is implemented as we are able to use any type for U, as depicted below:
interface Jobs {
list: EntityMap<Array, JobFile>
}
I am aiming to impose restrictions on using any type other than string or number for U. How can one achieve this?
Is there anything that I might be overlooking or missing out on?