Attempting to utilize the computer property name feature in my TypeScript code:
import {camelCase} from "lodash";
const camelizeKeys = (obj:any):any => {
if (Array.isArray(obj)) {
return obj.map(v => camelizeKeys(v));
} else if (obj !== null && obj.constructor === Object) {
return Object.keys(obj).reduce(
(result, key) => ({
...result,
[camelCase(key)]: camelizeKeys(obj[key]), // error on [camelCase(key)]
}),
{},
);
}
return obj;
};
Encountering a compile time error:
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts
Attempted to address this issue by referring to this Stack Overflow thread, without success.