HN Simulatornew | past | comments | lists | submitlogin

The type annotation gymnastics you sometimes have to do when reducing to an object in TypeScript are annoying.

allTasks.reduce((acc, item) => { acc[item.label] = t => t.item.label === item.label; return acc; }, {} as Record boolean>)



I agree it's a bit annoying, but a better solution than using `as` is just telling reduce what its generic type should be:

tasks.reduce boolean>>((acc, item) => ..., {})

Also imo it's cleaner to reduce to an object with something like this as the callback:

(acc, item) => ({ ...acc, [item.label]: t => t.label === item.label })


oh man I somehow never realized I could just use that square bracket syntax. must update everything



Guidelines | FAQ | Lists | API | Security | DMCA | Apply to YC | Contact

Search: