Here's a function I have:
const getQueryParams = (names) => {
const urlParams = new URLSearchParams(window.location.search)
return names.reduce((acc, curr) => {
return {
...acc,
[curr]: urlParams.get(curr),
}
}, {})
}
I want to define TypeScript types to achieve the following type for the output of the above function.
const params: Record<'a'|'b', string> = getQueryParams(['a', 'b'])
Can this be done? If so, how can it be accomplished?