Looking to create a function that takes an array of strings as input and returns an object with a key for each string in the input array?
Here is an example of how this can be implemented:
const getMyObject = (...keys: string[]) => keys.reduce((object, key) => ({
...object,
[key]: `some-computed-value-${key}`,
}),
{},
)
This allows you to safely write code like this:
const { keyA, keyB } = getMyObject('keyA', 'keyB');
If you're unsure about properly typing this function, we can explore different options.