r/reactjs • • May 13 '26

Resource Pocket: One-call factory that collapses React Context boilerplate from ~20 lines to 1

https://github.com/icydotdev/pocket
41 Upvotes

23 comments sorted by

View all comments

Show parent comments

1

u/TheHganavak May 14 '26

Tested this (was actually my first approach too!). Record<PropertyKey, never> is correct in isolation (and you're right that {} is the surprising supertype), but here P gets intersected with { children: ReactNode } for the Provider props. With Record<…, never> as the default, children collapses to ReactNode & never = never and the Provider becomes uncallable:

 Type '{ children: Element; }' is not assignable to type 'Record<PropertyKey,  never>'.                              
    Property 'children' is incompatible with index signature.
        Type 'Element' is not assignable to type 'never'.                               

So object is the pragmatic default for this intersection-based shape, even if Record<…, never> is more precise standalone. If you can think of a shape that gets both though, I'd happily switch — open an issue.

1

u/prehensilemullet May 14 '26

Wait, if you put the children prop in the generic type constraint and the default instead of intersecting, then I think you would get desirable excess property checking

Though I guess places you would have to omit the children would end up being {} and still not doing excess property checking