Skip to content

Commit

Permalink
[@redux/toolkit] Fix configure store reducers (#4330)
Browse files Browse the repository at this point in the history
* fix type breaking

* fix the middlwares type

* comment out unusable test
  • Loading branch information
Brianzchen committed Jun 8, 2022
1 parent 12b2715 commit 3a05283
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Expand Up @@ -5,6 +5,8 @@ import {
createReducer,
configureStore,
type Middleware,
type Store,
type Action,
} from '@reduxjs/toolkit';

describe('@redux/toolkit', () => {
Expand Down Expand Up @@ -63,6 +65,41 @@ describe('@redux/toolkit', () => {
configureStore({
reducer,
});

const store: Store<{
test: { ... },
test2: number,
...
}, Action<{ ... }>> = configureStore({
reducer: {
test: (a) => ({}),
test2: (a) => 2,
},
});

const failedStore: Store<{|
test: { ... },
test2: number,
// $FlowExpectedError[prop-missing] foo is missing
|}, Action<{ ... }>> = configureStore({
reducer: {
test: (a) => ({}),
test2: (a) => 2,
foo: () => 'bar',
},
});

// const failedStore2: Store<{
// test: { ... },
// // Expect this to fail but currently does not
// test2: string,
// ...
// }, Action<{ ... }>> = configureStore({
// reducer: {
// test: (a) => ({}),
// test2: (a) => 2,
// },
// });
});

test('full example', () => {
Expand Down
Expand Up @@ -49,7 +49,7 @@ declare module '@reduxjs/toolkit' {

// --------------------

declare type Middlewares<S> = $ReadOnlyArray<Middleware<{ ... }, S>>;
declare type Middlewares<S> = $ReadOnlyArray<Middleware<S, { type: any, ... }>>;

declare type DevToolsOptions = {|
/**
Expand Down Expand Up @@ -423,6 +423,8 @@ declare module '@reduxjs/toolkit' {
*/
declare type ConfigureEnhancersCallback = <S, A>(defaultEnhancers: $ReadOnlyArray<StoreEnhancer<S, A>>) => Array<StoreEnhancer<S, A>>;

declare type ReducersMapObject = <V>(V) => Reducer<V, Action<any>>;

/**
* Options for `configureStore()`.
*/
Expand All @@ -431,10 +433,7 @@ declare module '@reduxjs/toolkit' {
* 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> | {
[key: string]: Reducer<S, A>,
...
},
reducer: Reducer<S, A> | $ObjMap<S, ReducersMapObject>,
/**
* An array of Redux middleware to install. If not supplied, defaults to
* the set of middleware returned by `getDefaultMiddleware()`.
Expand Down

0 comments on commit 3a05283

Please sign in to comment.