Repository navigation
configureStore type error (TS2353) with preloadedState and/or middleware configuration #62416
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
SoumyadipYT-OSS commentedon Sep 8, 2025
In the terminal I am seeing the error:
index.d.mts
RyanCavanaugh commentedon Sep 8, 2025
We need an isolated repro for this; the issue may well be in
reduxjsSoumyadipYT-OSS commentedon Sep 8, 2025
I found the issue in index.d.mts file that is related with the Redux toolkit. Thanks Ryan Cavanaugh (@RyanCavanaugh)