Skip to content

Commit

Permalink
Merge pull request #4172 from aryaemami59/fix-4171
Browse files Browse the repository at this point in the history
Fix wrong state for injected slices when not declared via `withLazyLoadedSlices`
  • Loading branch information
EskiMojo14 committed Feb 8, 2024
2 parents 3befbb6 + 78067c5 commit ecee57c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/toolkit/src/combineSlices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface CombinedSliceReducer<
config?: InjectConfig,
): CombinedSliceReducer<
InitialState,
Id<DeclaredState & WithSlice<SliceLike<ReducerPath, String>>>
Id<DeclaredState & WithSlice<SliceLike<ReducerPath, State>>>
>

/**
Expand Down
17 changes: 17 additions & 0 deletions packages/toolkit/src/tests/combineSlices.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,21 @@ describe('type tests', () => {
(rootState: RootState, num: number) => rootState.inner,
)
})

test('correct type of state is inferred when not declared via `withLazyLoadedSlices`', () => {
// Related to https://github.com/reduxjs/redux-toolkit/issues/4171

const combinedReducer = combineSlices(stringSlice)

const withNumber = combinedReducer.inject(numberSlice)

expectTypeOf(withNumber).returns.toEqualTypeOf<{
string: string
number: number
}>()

expectTypeOf(withNumber(undefined, { type: '' }).number).toMatchTypeOf<
number
>()
})
})

0 comments on commit ecee57c

Please sign in to comment.