3 ms·
I run into this issue pretty often when using `Array.reduce`, I will do something like: Object.keys(someObject).reduce((acc, key) => ...., { const val = some
by _fat_santa 3y ago
I run into this issue pretty often when using `Array.reduce`, I will do something like:
Object.keys(someObject).reduce((acc, key) => ...., {
const val = someObject[key]
})
When I extract the value in Typescript, I always have to coerce the type like: someObject[key as keyof typeof someObject]
- andrewaylett 3y agoIf you're going to be indexing into the object with the key, you might be interested in `Object.entries()` instead -- it gives you all the keys paired with their values, so you don't have to look them up inside your reducer.