Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@redux/toolkit] Fix configure store reducers #4330

Merged
merged 3 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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