Skip to content

Commit a12524a

Browse files
committed
remove requirement for create to be a function
1 parent 62e96d5 commit a12524a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

docs/usage/custom-slice-creators.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Typically a creator will return a [single reducer definition](#single-definition
363363

364364
### Creator definitions
365365

366-
A creator definition contains the actual runtime logic for that creator. It's an object with a `type` property, a `create` method, and an optional `handle` method.
366+
A creator definition contains the actual runtime logic for that creator. It's an object with a `type` property, a `create` value (typically a function or set of functions), and an optional `handle` method.
367367

368368
It's passed to [`buildCreateSlice`](../api/createSlice#buildcreateslice) as part of the `creators` object, and the name used when calling `buildCreateSlice` will be the key the creator is nested under in the `create` object.
369369

@@ -413,9 +413,9 @@ const reducerCreator: ReducerCreator<typeof reducerCreatorType> = {
413413

414414
#### `create`
415415

416-
The `create` method is the function that will be attached to the `create` object, before it's passed to the `reducers` callback.
416+
The `create` value will be attached to the `create` object, before it's passed to the `reducers` callback.
417417

418-
Because it's a function, the `this` value will be the final `create` object when called (assuming a `create.creator()` call). It also could have additional methods attached.
418+
If it's a function, the `this` value will be the final `create` object when called (assuming a `create.creator()` call). It also could have additional methods attached, or be an object with methods.
419419

420420
See the [Further examples](#further-examples) section for some examples of these.
421421

@@ -605,7 +605,7 @@ The `ReducerCreatorEntry<Create, Exposes>` utility has two type parameters:
605605

606606
#### `Create`
607607

608-
The signature of the `create` method of the creator definition.
608+
The type of the `create` value of the creator definition (typically a function signature).
609609

610610
:::caution `CaseReducers`
611611

packages/toolkit/src/createSlice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface ReducerDefinition<
4747
}
4848

4949
export type ReducerCreatorEntry<
50-
Create extends (...args: any[]) => any,
50+
Create,
5151
Exposes extends {
5252
actions?: Record<string, unknown>
5353
caseReducers?: Record<string, unknown>
@@ -160,14 +160,14 @@ export type ReducerCreators<
160160
} & {
161161
[CreatorName in keyof CreatorMap as SliceReducerCreators<
162162
State,
163-
any,
163+
never,
164164
Name,
165165
ReducerPath
166166
>[CreatorMap[CreatorName]]['create'] extends never
167167
? never
168168
: CreatorName]: SliceReducerCreators<
169169
State,
170-
any,
170+
never,
171171
Name,
172172
ReducerPath
173173
>[CreatorMap[CreatorName]]['create']

0 commit comments

Comments
 (0)