Expose a reusable store type for typed utilities and hooks.
Application-wide typing
Redux Toolkit · Type Alias
Store is the type of a Redux store instance. In TypeScript, derive it from the configured store with typeof store, alongside inferred state and dispatch types.
Store represents the Redux store instance produced by the configured setup. Derive application-specific types from that instance: use typeof store for the store type, ReturnType<typeof store.getState> for state, and typeof store.dispatch for dispatch, so middleware and reducer changes remain reflected automatically.
export type AppStore = typeof storeThe store-derived type describes a Redux store instance with its configured state and dispatch behavior.
RootState is obtained from the return value of the store's getState method.AppDispatch is the type of the configured store's dispatch function.AppStore is directly inferred as the type of the store variable.configureStore determines the inferred state shape.RootState from store.getState() rather than duplicating the state shape manually.AppDispatch from the store so middleware-provided dispatch overloads are retained.import { configureStore } from '@reduxjs/toolkit'
const store = configureStore({
reducer: {
counter: (state = 0, action: { type: string }) =>
action.type === 'increment' ? state + 1 : state
}
})
export type AppStore = typeof store
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
store.dispatch({ type: 'increment' })
console.log(store.getState())Creates a configured store and derives its store, state, and dispatch types directly from the resulting instance.
Application-wide typing
State selection
Middleware-aware dispatch
Store refactoring
Store is the type of the Redux store instance, not the state value itself. In TypeScript, derive it with typeof store, while deriving state with ReturnType<typeof store.getState> and dispatch with typeof store.dispatch.
Follow-up: Why derive these types after creating the store? Because the inferred types track the configured reducers and middleware, avoiding stale manually maintained declarations.
Use ReturnType<typeof store.getState> for RootState, typeof store.dispatch for AppDispatch, and typeof store for AppStore. These declarations infer the types from the actual configured store.
Follow-up: What changes when middleware is added? The inferred dispatch type incorporates middleware-contributed dispatch behavior, including thunk-related overloads.
A configured store is created with configureStore, which infers state from its reducer configuration. Extracting types from the resulting store keeps them synchronized when reducers or middleware settings change.
Follow-up: How should server-rendered applications type a store factory? Use ReturnType<typeof makeStore> for the store type, then derive state and dispatch from that type.
configureStoreRootStateAppDispatchAppStoregetStatedispatchmiddleware