Skip to content

configureStore type error (TS2353) with preloadedState and/or middleware configuration #62416

Closed

Description

🔎 Search Terms

Redux Toolkit configureStore, TypeScript TS2353, preloadedState type error, middleware tuple, tsconfig baseUrl, folder conflict

🕗 Version & Regression Information

This issue appears to have started after I upgraded my project dependencies to @reduxjs/toolkit v2 and TypeScript.
I have attempted to reproduce this issue using the latest nightly build of TypeScript, but the error persists.

⏯ Playground Link

No response

💻 Code

The code of store.ts file in my project

import { configureStore } from "@reduxjs/toolkit";
import counterReducer from "../features/counter/counterSlice";
import todoReducer from "../features/todo/todoSlice";

// --- Load persisted state from localStorage ---
const loadState = () => {
  try {
    const serializedState = localStorage.getItem("reduxState");
    if (serializedState === null) {
      return undefined;
    }
    return JSON.parse(serializedState);
  } catch {
    // Return undefined in case of any error to let the reducers
    // initialize to their default state.
    return undefined;
  }
};

// --- Create the store with preloadedState ---
const preloadedState = loadState();

export const store = configureStore({
  reducer: {
    counter: counterReducer,
    todo: todoReducer,
  },
  preloadedState, // This is optional and correctly handles `undefined`.
});

// --- Define types AFTER store is created ---
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

// --- Save state to localStorage ---
const saveState = (state: RootState) => {
  try {
    const serializedState = JSON.stringify(state);
    localStorage.setItem("reduxState", serializedState);
  } catch {
    // Ignore write errors
  }
};

// --- Subscribe to store changes ---
store.subscribe(() => {
  saveState(store.getState());
});

🙁 Actual behavior

When attempting to configure a Redux store using configureStore with specific options, I receive a TypeScript compilation error (TS2353). The error message states, "Object literal may only specify known properties, and 'preloadedState' does not exist in type '...'" or a similar error pointing to the middleware property. This occurs despite the fact that preloadedState and middleware are documented properties of the ConfigureStoreOptions interface. The compiler seems unable to correctly infer the type of the configuration object.

🙂 Expected behavior

The configureStore function should correctly accept the configuration object, including the preloadedState and other documented options, and infer the correct types as per the Redux Toolkit documentation, without throwing a compilation error.

Additional information about the issue

No response

Activity

  1. SoumyadipYT-OSS commented on Sep 8, 2025

    @SoumyadipYT-OSS
    Author

    In the terminal I am seeing the error:

    Object literal may only specify known properties, and 'counter' does not exist in type 'Reducer<{ counter: CounterState; todo: TodoState; }, UnknownAction, any>'.
    
    The expected type comes from property 'reducer' which is declared here on type 'ConfigureStoreOptions<{ counter: CounterState; todo: TodoState; }, UnknownAction, Tuple<[ThunkMiddleware<{ counter: CounterState; todo: TodoState; }, UnknownAction>]>, Tuple<...>, any>'

    index.d.mts

    interface ConfigureStoreOptions<S = any, A extends Action = UnknownAction, M extends Tuple<Middlewares<S>> = Tuple<Middlewares<S>>, E extends Tuple<Enhancers> = Tuple<Enhancers>, P = S> {
        /**
         * A single reducer function that will be used as the root reducer, or an
         * object of slice reducers that will be passed to `combineReducers()`.
         */
        reducer: Reducer<S, A, P> | ReducersMapObject<S, A, P>;   // → this line
        /**
         * An array of Redux middleware to install, or a callback receiving `getDefaultMiddleware` and returning a Tuple of middleware.
         * If not supplied, defaults to the set of middleware returned by `getDefaultMiddleware()`.
         *
         * @example `middleware: (gDM) => gDM().concat(logger, apiMiddleware, yourCustomMiddleware)`
         * @see https://redux-toolkit.js.org/api/getDefaultMiddleware#intended-usage
         */
  2. RyanCavanaugh commented on Sep 8, 2025

    @RyanCavanaugh
    Member

    We need an isolated repro for this; the issue may well be in reduxjs

  3. SoumyadipYT-OSS commented on Sep 8, 2025

    @SoumyadipYT-OSS
    Author

    I found the issue in index.d.mts file that is related with the Redux toolkit. Thanks Ryan Cavanaugh (@RyanCavanaugh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions