Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSelector seems to have no type awareness #1358

Closed
IhsanMujdeci opened this issue Jul 22, 2019 · 5 comments
Closed

useSelector seems to have no type awareness #1358

IhsanMujdeci opened this issue Jul 22, 2019 · 5 comments

Comments

@IhsanMujdeci
Copy link

IhsanMujdeci commented Jul 22, 2019

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 :)

@IhsanMujdeci IhsanMujdeci changed the title useSelect seems to have no type awareness useSelector seems to have no type awareness Jul 22, 2019
@IhsanMujdeci
Copy link
Author

After inspection fo your code I can see its not possible at the moment to make this happen as your lib is written in purejs and you use jsdocs for ide intelisense and you can't make this feature happen with the current language. If im wrong please correct me

@timdorr
Copy link
Member

timdorr commented 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.

@timdorr timdorr closed this as completed Jul 22, 2019
@IhsanMujdeci
Copy link
Author

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

@olejorgenb
Copy link

Anyone gotten this to work for javscript in webstorm? I tried providing the typescript definitions like described in https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files but no luck.

@aleccaputo
Copy link

@olejorgenb after installing @types/react-redux webstorm worked with type ahead as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants