I'm trying to reduce Object.keys, like this:
const example = { hello: true }
Object.keys(example).reduce((acq, key) => {
const value = example[key]
return acq
}, {})
For some reason I am getting a type error under example[key]
(parameter) key: string
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ hello: boolean; }'. No index signature with a parameter of type 'string' was found on type '{ hello: boolean; }'.(7053)
I created my own getKeys function with a generic that has the typings I'd expect:
function getKeys <T>(g: T) {
return Object.keys(g) as (keyof T)[]
}
const example = { hello: true }
getKeys(example).reduce((acq, key) => {
const value = example[key]
return acq
}, {})
However I'm looking if this is possible without wrapping Object.keys.