In my current scenario, I am encountering a situation where I need to assign the keys of an object as values from another array. Here is an example:
const temp: { [key in typeof someArray[number] ]: string[] } = {
'animal': ['dog', 'cat']
} // However, there is an error stating that some properties from type birds are missing...
const someArray = [ 'animals', 'birds' ] as const;
This requirement dictates that the temp object must include keys for all the values within the array. The challenge lies in the fact that I want to allow optional values, meaning if a key exists, it should match one of the array values. If there are values that do not correspond to keys, there should be no issues
const temp: { [key in typeof someArray[number] ]: string[] } = {
'animal': ['dog', 'cat']
} // In this case, there should be no error
const temp: { [key in typeof someArray[number] ]: string[] } = {
'animal': ['dog', 'cat'],
'random': ['random_1']
} // However, this scenario should trigger an error