Closed joekrill closed 1 month ago
We presumably never just thought to export it - there's been a lot of that going around :) (See #3962 , #4448 , etc.)
If exporting this helps, yeah, please file a PR!
@joekrill Can you show what your tsconfig.json
file looks like?
@aryaemami59 this is my tsconfig.json
:
{
"compilerOptions": {
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noUncheckedIndexedAccess": true,
"strict": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"outDir": "build",
"sourceMap": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"target": "es2020",
"composite": true,
"preserveWatchOutput": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"exclude": ["build/"]
}
@joekrill
Can you run this command and try again to see if it fixes the issue:
npm install https://pkg.csb.dev/reduxjs/redux-toolkit/commit/06a30ee4/@reduxjs/toolkit
@aryaemami59 That build seems to have fixed the issue! Should I hold off on creating a PR to explicitly export the UpdateDefinitions
type? Or is it still worth putting up a PR for that?
@joekrill That would be up to the maintainers but I would rather not export a type unless we absolutely have to.
I'm seeing a similar problem with the lack of UpdateDefinitions
export. My library that uses enhanceEndpoints
builds fine, but when I import the enhanced API into another package, Typescript infers its type to be any
.
A dumb workaround I have is to import and export UpdateDefinitions
in my library like this:
import { UpdateDefinitions } from '@reduxjs/toolkit/dist/query/endpointDefinitions';
import { myApi as api } from './api';
export { UpdateDefinitions };
export const myApi = api.enhanceEndpoints({});
~That fixes the type inference in the consuming package. Maybe I'm missing something simple in my tsconfig, but I haven't found a better solution yet.~
Actually, this only suppresses the error, but types are still wrong. It looks like the problem happens when moduleResolution
of the consuming package is set to bundler
. Imports from @reduxjs/toolkit/dist/...
don't work in that case.
@joekrill That would be up to the maintainers but I would rather not export a type unless we absolutely have to.
@aryaemami59 Well the reason I ask is because if the changes in the branch you asked me to try will eventually get merged, then that seems to fix the problem and there would be no need for me to create an additional PR for it. So I guess what I'm really asking is: do you expect the changes in that branch to make it into master?
@joekrill yeah, Arya's been doing a lot of good work fixing up the various TS interop issues. I haven't had time yet to review any of them myself, but sounds like they're pretty close at this point.
@joekrill Yes. That PR is ready. It just needs to be reviewed and yes I expect it will get merged at some point.
@mchill The issue is you should not be importing anything from the dist
folder.
@mchill The issue is you should not be importing anything from the
dist
folder.
Totally agree, and I'm not directly, but the generated type of enhanceEndpoints
looks like this:
import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<string | FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, import("@reduxjs/toolkit/dist/query/endpointDefinitions").UpdateDefinitions<{}, never, never>, string, never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/dist/query/react").reactHooksModuleName>;
Both UpdateDefinitions
and reactHooksModuleName
are imported from dist/
. Then when I publish those generated types to a package and import the package into another with "moduleResolution": "bundler"
, it obviously doesn't work.
Maybe there's something I should be doing differently to generate better types. I did find a real workaround by setting paths
in the consumer package's tsconfig.json
, but I'm aware of how bad practice it is.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@reduxjs/toolkit/dist/*": ["node_modules/@reduxjs/toolkit/dist/*"]
}
}
}
Haven't tried out your PR yet, but hopefully that fixes it.
@mchill Can you try out the PR and let me know if it fixes the issue you're having?
It does! But it introduced another type error when adding dynamicMiddleware
to my store.
Exported variable 'store' has or is using name 'DynamicDispatch' from external module "/path/to/project/node_modules/@reduxjs/toolkit/dist/index" but cannot be named.
@mchill Can you share the code snippet? And are you sure you're not importing from the dist
folder?
Sure, here's a very stripped down example. Definitely no dist imports. https://github.com/mchill/rtk-demo
@mchill Thanks for the repro, I fixed the issue, can you try this and let me know if it fixes the problem?
npm install https://pkg.csb.dev/reduxjs/redux-toolkit/commit/51afa9fc/@reduxjs/toolkit
Everything looks good to me with that version.
I'm trying to upgrade to Redux Toolkit v2 but running into a problem that I'm pretty sure is caused by the
UpdateDefinitions
type not being exported from@reduxjs/toolkit/query
.I have a monorepo with a separate package for my API endpoint, which is further split up into smaller chunks.
@reduxjs/toolkit
is a peer dependency in that package.I have a base API defined like this:
And the additional API chunks are handled similar to this:
This was working fine with v1, but after trying to upgrade to v2 I'm getting the error (at the
authApi
definition):If I remove the
enhanceEndpoints
call (and leave just theinjectEndpoints
call) the issues goes away, but then I can no longer use the "Permissions" tag inprovideTags
. I'm fairly certain I've narrowed down the problem to the fact that theUpdateDefinitions
type used byenhanceEndpoints
is not exported by@reduxjs/toolkit/query
. All the other referenced types seem to be exported except for this one. Is there a specific reason for omitting it? Or was it an oversight? Would it be worth me putting up a PR to export it?