I've already had a function working correctly.
const camelizeKeys = (obj: any): any => {
if (Array.isArray(obj)) {
return obj.map((v) => camelizeKeys(v)) // camelizeKeys is a function in lodash.
} else if (obj != null && obj.constructor === Object) {
return Object.keys(obj).reduce(
(result, key) => ({
...result,
[camelCase(key)]: camelizeKeys(obj[key])
}),
{}
)
}
return obj
}
However, it used explicit any in the type of parameter and return value. Is it possible to express the type in a better way (e.g. infer the type of return value from the parameter type)?