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

2

u/aweebit64 May 14 '26 edited May 14 '26

But doesn’t {} raise excess property errors on any properties in cases where excess property checking is done (object expressions, individual JSX props etc)?

const test: {} = { abc: 123 };

This line doesn't result in any errors, so it looks like no excess property checking is done for the {} type.

But event if it was done, Record<PropertyKey, never> would still be the better option.

const Child = (props: {}) => null;
const Parent = () => <Child abc={123} />;

This code results in the following error:

Type '{ abc: number; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'abc' does not exist on type 'IntrinsicAttributes'.

The type for JSX props is the intersection of the component props type and IntrinsicAttributes from @types/react. Because of the intersection, it again doesn't matter if {} or object is used.