question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useSelector seems to have no type awareness

See original GitHub issue

When making my own selector with typing const practitionerAvailability = (state): availabilities => state.practitioner.availability.availabilities;

the returned type from useSelector is still type any when i do something like. const a = useSelector(practitionerAvailability).

I made a little example in typescript which solves this

function useTypedSelector<T>(selector: (any)=>T): T {
    return useSelector(selector)
}

Is there any way you guys could include the behaviour baked into the useSelector function. Thanks 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
IhsanMujdecicommented, Jul 23, 2019

Thanks I was being silly didn’t install @types/react-redux as a dependency. Thanks for pointing me int he right direction

3reactions
timdorrcommented, Jul 22, 2019

If you’re using TypeScript, we don’t maintain the types here. Those are on the DefinitelyTyped repo, so check with them for their support resources.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Redux useSelector typescript type for state
It is set by default as unknown so I get an error when I try to return state.SLICE_NAME ( Error: Object is of...
Read more >
Redux Gotchas — useSelector - Level Up Coding
The selector function — stateSelector — is called whenever there is a state change to the subscribed property. State property — counter —...
Read more >
Hooks - React Redux
When an action is dispatched, useSelector() will do a reference comparison of the previous selector result value and the current result value.
Read more >
useSelector vs connect (react-redux) - Sam Dawson
React-redux hooks like and the can have the same outcomes. The main difference between them is their ability to nudge (guide) the way...
Read more >
`state` in `useSelector` is undefined. How do I get around this?
However I'm not a React guy so I googled it, and it seems that you can tell useSelector a type, as user signsAndWonders...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found