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

[TS2742] The inferred type of '...' cannot be named without a reference to ... #4448

Closed
ryuujo1573 opened this issue Jun 7, 2024 · 10 comments

Comments

@ryuujo1573
Copy link

ryuujo1573 commented Jun 7, 2024

Related to microsoft/TypeScript#58743

It is not working if I try to export reducers/slices from a package.

Is this an actual TS issue?

Here's a possible reproduction

src/logic/client/user.ts:11:7 - error TS2742: The inferred type of 'userSlice' cannot be named without a reference to '../../../node_modules/@reduxjs/toolkit/dist/createSlice'. This is likely not portable. A type annotation is necessary.
@telephant
Copy link

same here

@telephant
Copy link

emm, don't export nikkiSlice, only export nikkiReducer

@aryaemami59
Copy link
Contributor

Related to #3962.

@aryaemami59
Copy link
Contributor

It seems like in your case we have to export the CaseReducerDefinition interface from the main index.d.ts file.

Side note: It seems like if a type is exported from an internal .d.ts file, but not exported from index.d.ts, then the error becomes: The inferred type of 'nikkiSlice' cannot be named without a reference to '../../node_modules/@reduxjs/toolkit/dist/createSlice'. This is likely not portable. A type annotation is necessary.

But if that same type is not exported at all the error message becomes much clearer like this: Exported variable 'nikkiSlice' has or is using name 'CaseReducerDefinition' from external module "RTK-issue-3962/node_modules/.pnpm/@[email protected]/node_modules/@reduxjs/toolkit/dist/createSlice" but cannot be named.
which actually tells us which type is the problematic one.

@EskiMojo14
Copy link
Collaborator

@aryaemami59 that makes sense, thanks. i think we wouldn't be against exporting CaseReducerDefinition - in fact my open PR https://github.com/reduxjs/redux-toolkit/pull/3894/files#diff-5278ccae8e99ae0373490ef372d1953e0f3da303d948485ef7e00bd7de7fffa3 exports more that we can export just in case.

@aryaemami59
Copy link
Contributor

@EskiMojo14 Wonderful, I have a list of types that need to be exported, thankfully they're not that many (as of now, might add more to the list if I discover more problems), will hopefully put up a PR soon for a partial fix.

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`
@aryaemami59
Copy link
Contributor

aryaemami59 commented Jul 9, 2024

Can you run this command and try again to see if it fixes the issue:

pnpm add https://pkg.csb.dev/reduxjs/redux-toolkit/commit/06a30ee4/@reduxjs/toolkit

@atsiapas-mellon
Copy link

Can you run this command and try again to see if it fixes the issue:

pnpm add https://pkg.csb.dev/reduxjs/redux-toolkit/commit/06a30ee4/@reduxjs/toolkit

It did fix the issue for me. Thank you.

@glasody
Copy link

glasody commented Jul 23, 2024

for me adding "baseUrl": ".", to tsconfig fixed it

@markerikson
Copy link
Collaborator

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

7 participants