Skip to content

Commit

Permalink
Add Type tests for reduxjs#4171
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Feb 8, 2024
1 parent 2da5f0d commit fcc85d9
Showing 1 changed file with 17 additions and 0 deletions.
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 | undefined
>()
})
})

0 comments on commit fcc85d9

Please sign in to comment.