troch / reinspect

Use redux devtools to inspect useState and useReducer :mag_right:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useReducer's type definition invalid: can't supply id as 3rd param

0xdevalias opened this issue · comments

I'm not 100% if this is a bug, or a me problem, but it seems that your TS definitions imply that i can call useReducer with 3 params, and have it take the id from the 3rd param:
node_modules/reinspect/types/useReducer.d.ts

export declare function useReducer<R extends Reducer<any, any>>(reducer: R, initialState: ReducerState<R>, id?: string | number): [ReducerState<R>, Dispatch<ReducerAction<R>>];

But when running the code, and debugging, it looks like that isn't actually the case:
image

I assume the current 'solution'/workaround is what is referred to in the README, namely:

If no id is supplied, the hook won't be connected to dev tools. You can use identity function (state => state) as 3rd parameter to mock lazy initialization.

If that is intended as the only way to use this, then updating the type defs to disallow passing id as the 3rd param would be great.

Of course I realise it's a bug in my own code just after I make an issue for it.. seems the variable I was passing as the identifier was actually undefined due to my own bug, so the type definitions seem to work correctly passing id as the 3rd or 4th param.