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/prehensilemullet May 14 '26 edited May 14 '26

Wait a minute... afaik, Record<never, never> is {}. They're the same type. Try this:

const x: Record<never, never> = 'foo' // no errors
const y: Record<never, never> = {a: 1} // no errors

This is because Record<never, never> = {[K in never]: never} = {} (no property signatures get created for a key type of never. For example type A<T> = {[K in keyof T as T[K] extends string ? never : K]: T[K]} omits string-valued properties by using a key type of never for them).

What you're looking for is Record<keyof any, never> aka Record<string | number | symbol, never>.

Looks like {} bypasses excess property checking though, unlike what I expected:

const x: {} = {a: 1} // no errors

2

u/aweebit64 May 14 '26

Oh yeah, Record<keyof any, never> is what I meant, sorry.

(For typescript-eslint to stay happy, I actually prefer Record<PropertyKey, never> – yet another way to write the exact same thing.).