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

The inferred type of [...] cannot be named without a reference to [...] buildHooks.js #3983

Closed
thovden opened this issue Dec 16, 2023 · 5 comments

Comments

@thovden
Copy link

thovden commented Dec 16, 2023

Porting from RTK Toolkit 1.9.7 to 2.0.1 I get the following problem for my RTK Query endpoints when exporting the generated hooks.

E.g.,

The inferred type of 'useLazyGetNlpQuery' cannot be named without a reference to '../../../../node_modules/@reduxjs/toolkit/dist/query/react/buildHooks.js'. This is likely not portable. A type annotation is necessary.ts(2742)

This error occurs on all endpoints, not just this one. I do not import or use buildHooks anywhere in my code.

@thovden
Copy link
Author

thovden commented Jan 14, 2024

I refactored my code today and got around this problem. The two things I did was:

  1. Don't export the RTKQuery generated hooks, export the API instead and use e.g., nlpApi.useLazyGetNlpQuery
  2. I had some exports where I spread a slices onto another object - e.g., const features = { ...slice, ...}. This caused "cannot be named" issues.

I'm going to close this issue now. Keep up the good work!

@thovden thovden closed this as completed Jan 14, 2024
@shermify
Copy link

shermify commented Jan 17, 2024

This is still valid ECMAScript, so there is a typescript problem here. Managing exports is important for large projects. I'm not sure exactly where the responsibility falls but I've opened an issue here with more detail and it's in the bugfix queue. #4066

aryaemami59 added a commit to aryaemami59/redux-toolkit that referenced this issue Jun 8, 2024
- This should serve as a partial fix for reduxjs#3962, reduxjs#4448, reduxjs#3983, reduxjs#4066, reduxjs#4108, reduxjs#4401
- Here is the list of the problematic (now exported) types:
  From `@reduxjs/toolkit`:
  - `CombinedSliceReducer`
  - `CaseReducerDefinition`
  - `Id` renamed to `TSHelpersId`
  - `UncheckedIndexedAccess`
  - `ReducerWithInitialState`
  - `CaseReducerDefinition`
  - `Id` renamed to `TSHelpersId`
  - `UncheckedIndexedAccess`
  - `ReducerWithInitialState`
  From `@reduxjs/toolkit/query/react`:
  - `UseLazyQuery`
  - `UseQuery`
  - `QueryHooks`
@Romanmed2000
Copy link

i have same problem/ i use official example by redux https://github.com/reduxjs/redux-templates/blob/master/packages/vite-template-redux/src/features/quotes/quotesApiSlice.ts and have error
The inferred type of useGetQuotesQuery cannot be named without a reference to
../../../../node_modules/@reduxjs/toolkit/dist/query/react/buildHooks
. This is likely not portable. A type annotation is necessary.
after 6 mons fix not apply? need correct example?

@EskiMojo14
Copy link
Collaborator

@Romanmed2000 if you install the build from here, does that fix the issue?

after 6 mons fix not apply?

We have a PR #4467 open from @aryaemami59 aiming to fix it, but as the size of the PR may tell you, it's not an easy fix. It's taken him months of work so far.

@markerikson
Copy link
Collaborator

Fixed in https://github.com/reduxjs/redux-toolkit/releases/tag/v2.2.7 !

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

5 participants