reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.7k stars 1.17k forks source link

ReducerWithInitialState is not portlable according to TS #4108

Closed krutoo closed 2 months ago

krutoo commented 9 months ago

Hi, in my project i use toolkit 2.0.0 and i have type check build during emit declaration files only with isolatedModules: true option in tsconfig:

{
  "compilerOptions": {
    "target": "ES2021",
    "moduleResolution": "Bundler",
    "baseUrl": ".",
    "jsx": "react-jsx",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noUncheckedIndexedAccess": true,
    "outDir": "dist/types",
    "declaration": true,
    "sourceMap": true,
    "emitDeclarationOnly": true,
    "isolatedModules": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "*.test.*", "**/__test__/*"]
}

i have error:

src/internal/core/redux/index.ts:64:14 - error TS2742: The inferred type of 'reducer' cannot be named without a reference to '../../../../node_modules/@reduxjs/toolkit/dist/createReducer'. This is likely not portable. A type annotation is necessary.

Can we add export of ReducerWithInitialState from entry point of package?

krutoo commented 9 months ago

i have reducer like:

export const reducer = createReducer({/* ... */}, () => {/* ... */})
shermify commented 8 months ago

It's a known issue when declaration=true with ES modules https://github.com/reduxjs/redux-toolkit/issues/4066

aryaemami59 commented 3 months ago

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
markerikson commented 2 months ago

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

krutoo commented 2 months ago

@markerikson thanks a lot, (looks like release title is 2.2.6 for tag 2.2.7)

EskiMojo14 commented 2 months ago

@krutoo fixed, thanks