Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolkit/src/tests/configureStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('configureStore', async () => {
let dummyEnhancerCalled = false

const dummyEnhancer: StoreEnhancer =
(createStore: StoreEnhancerStoreCreator) =>
(createStore) =>
(reducer, ...args: any[]) => {
dummyEnhancerCalled = true

Expand Down
19 changes: 9 additions & 10 deletions packages/toolkit/src/tests/configureStore.typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ const _anyMiddleware: any = () => () => () => {}
})

{
type SomePropertyStoreEnhancer = StoreEnhancer<{ someProperty: string }>

const somePropertyStoreEnhancer: SomePropertyStoreEnhancer = (next) => {
const somePropertyStoreEnhancer: StoreEnhancer<{ someProperty: string }> = (
next
) => {
return (reducer, preloadedState) => {
return {
...next(reducer, preloadedState),
Expand All @@ -170,13 +170,9 @@ const _anyMiddleware: any = () => () => () => {}
}
}

type AnotherPropertyStoreEnhancer = StoreEnhancer<{
const anotherPropertyStoreEnhancer: StoreEnhancer<{
anotherProperty: number
}>

const anotherPropertyStoreEnhancer: AnotherPropertyStoreEnhancer = (
next
) => {
}> = (next) => {
return (reducer, preloadedState) => {
return {
...next(reducer, preloadedState),
Expand All @@ -187,7 +183,10 @@ const _anyMiddleware: any = () => () => () => {}

const store = configureStore({
reducer: () => 0,
enhancers: [somePropertyStoreEnhancer, anotherPropertyStoreEnhancer],
enhancers: [
somePropertyStoreEnhancer,
anotherPropertyStoreEnhancer,
] as const,
})

expectType<Dispatch & ThunkDispatch<number, undefined, AnyAction>>(
Expand Down
10 changes: 8 additions & 2 deletions packages/toolkit/src/tsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ export type ExtractDispatchExtensions<M> = M extends MiddlewareArray<
? ExtractDispatchFromMiddlewareTuple<[...M], {}>
: never

export type ExtractStoreExtensions<E> = E extends any[]
? UnionToIntersection<E[number] extends StoreEnhancer<infer Ext> ? Ext extends {} ? Ext : {} : {}>
export type ExtractStoreExtensions<E> = E extends readonly any[]
? UnionToIntersection<
E[number] extends StoreEnhancer<infer Ext>
? Ext extends {}
? Ext
: {}
: {}
>
: {}

/**
Expand Down