@@ -7,47 +7,44 @@ import {
77} from '@reduxjs/toolkit'
88import type {
99 PayloadAction ,
10- Slice ,
1110 SliceCaseReducers ,
12- UnknownAction ,
11+ ValidateSliceCaseReducers ,
1312} from '../..'
1413import type { EntityId , EntityState , IdSelector } from '../models'
15- import type { BookModel } from './fixtures/book'
14+ import { AClockworkOrange , type BookModel } from './fixtures/book'
1615
1716describe ( 'Entity Slice Enhancer' , ( ) => {
18- let slice : Slice < EntityState < BookModel , BookModel [ 'id' ] > >
17+ let slice : ReturnType < typeof entitySliceEnhancer < BookModel , string > >
1918
2019 beforeEach ( ( ) => {
21- const indieSlice = entitySliceEnhancer ( {
20+ slice = entitySliceEnhancer ( {
2221 name : 'book' ,
2322 selectId : ( book : BookModel ) => book . id ,
2423 } )
25- slice = indieSlice
2624 } )
2725
2826 it ( 'exposes oneAdded' , ( ) => {
29- const book = {
30- id : '0' ,
31- title : 'Der Steppenwolf' ,
32- author : 'Herman Hesse' ,
33- }
34- const action = slice . actions . oneAdded ( book )
35- const oneAdded = slice . reducer ( undefined , action as UnknownAction )
36- expect ( oneAdded . entities [ '0' ] ) . toBe ( book )
27+ const action = slice . actions . oneAdded ( AClockworkOrange )
28+ const oneAdded = slice . reducer ( undefined , action )
29+ expect ( oneAdded . entities [ AClockworkOrange . id ] ) . toBe ( AClockworkOrange )
3730 } )
3831} )
3932
40- interface EntitySliceArgs < T , Id extends EntityId > {
33+ interface EntitySliceArgs <
34+ T ,
35+ Id extends EntityId ,
36+ CaseReducers extends SliceCaseReducers < EntityState < T , Id > > ,
37+ > {
4138 name : string
4239 selectId : IdSelector < T , Id >
43- modelReducer ?: SliceCaseReducers < T >
40+ modelReducer ?: ValidateSliceCaseReducers < EntityState < T , Id > , CaseReducers >
4441}
4542
46- function entitySliceEnhancer < T , Id extends EntityId > ( {
47- name ,
48- selectId ,
49- modelReducer ,
50- } : EntitySliceArgs < T , Id > ) {
43+ function entitySliceEnhancer <
44+ T ,
45+ Id extends EntityId ,
46+ CaseReducers extends SliceCaseReducers < EntityState < T , Id > > = { } ,
47+ > ( { name , selectId , modelReducer } : EntitySliceArgs < T , Id , CaseReducers > ) {
5148 const modelAdapter = createEntityAdapter ( {
5249 selectId,
5350 } )
0 commit comments