Skip to content

Commit cd9f0f9

Browse files
committed
test attached method returning definition
1 parent 8787733 commit cd9f0f9

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Diff for: packages/toolkit/src/createSlice.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ type RecursiveExtractDefinition<
285285
}[keyof Definitions]
286286
: never)
287287

288-
export type ReducerDefinitionsForType<Type extends RegisteredReducerType> = {
288+
type ReducerDefinitionsForType<Type extends RegisteredReducerType> = {
289289
[CreatorType in keyof SliceReducerCreators]:
290290
| RecursiveExtractDefinition<
291291
ReturnType<SliceReducerCreators[CreatorType]['create']>,

Diff for: packages/toolkit/src/tests/createSlice.test.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {
4444
getLog,
4545
} from 'console-testing-library/pure'
4646
import type { IfMaybeUndefined, NoInfer } from '../tsHelpers'
47-
4847
enablePatches()
4948

5049
type CreateSlice = typeof createSlice
@@ -1321,10 +1320,22 @@ describe('createSlice', () => {
13211320
test('batchable', () => {
13221321
const batchedCreator: ReducerCreator<typeof batchedCreatorType> = {
13231322
type: batchedCreatorType,
1324-
create(this: ReducerCreators<any>, reducer: CaseReducer<any, any>) {
1325-
return this.preparedReducer(prepareAutoBatched(), reducer) as any
1326-
},
1323+
create: Object.assign(
1324+
function (
1325+
this: ReducerCreators<any>,
1326+
reducer: CaseReducer<any, any>
1327+
) {
1328+
return this.preparedReducer(prepareAutoBatched(), reducer) as any
1329+
},
1330+
{
1331+
test() {
1332+
return { _reducerDefinitionType: batchedCreatorType } as const
1333+
},
1334+
}
1335+
),
1336+
handle() {},
13271337
}
1338+
13281339
const createBatchSlice = buildCreateSlice({
13291340
creators: { batchedReducer: batchedCreator },
13301341
})
@@ -1548,6 +1559,7 @@ declare module '@reduxjs/toolkit' {
15481559
(payload: Payload) => { payload: Payload; meta: unknown }
15491560
>
15501561
>
1562+
test(): ReducerDefinition<typeof batchedCreatorType>
15511563
}>
15521564
}
15531565
}

0 commit comments

Comments
 (0)