I am trying to extract the key map from an object, and although I have created a function for this purpose, TypeScript is not happy with it. How can I resolve this issue without using acc: any
?
const origin = {
a: 1,
b: 'string',
c: () => {}
};
function getObjKeyMap<T>(obj: T) {
return Object.keys(obj).reduce((acc, k) => {
/* Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.ts(7053) */
acc[k] = k;
return acc;
}, {});
}
const keyMap = getObjKeyMap(origin);