import type { Reducer } from 'redux'; import { ActionCreatorWithoutPayload, PayloadAction, PrepareAction, _ActionCreatorWithPreparedPayload } from '.'; import { DeepReadonly } from '../../types'; import { PayloadActionCreator } from './createAction'; import { CaseReducer, CaseReducers } from './createReducer'; import { ActionReducerMapBuilder } from './mapBuilders'; import { NoInfer } from './tsHelpers'; /** * An action creator attached to a slice. * * @deprecated please use PayloadActionCreator directly * * @public */ export type SliceActionCreator

= PayloadActionCreator

; /** * The return value of `createSlice` * * @public */ export interface Slice = SliceCaseReducers, Name extends string = string> { /** * The slice name. */ name: Name; /** * The slice's reducer. */ reducer: Reducer>; /** * Action creators for the types of actions that are handled by the slice * reducer. */ actions: CaseReducerActions; /** * The individual case reducer functions that were passed in the `reducers` parameter. * This enables reuse and testing if they were defined inline when calling `createSlice`. */ caseReducers: SliceDefinedCaseReducers; /** * Provides access to the initial state value given to the slice. * If a lazy state initializer was provided, it will be called and a fresh value returned. */ getInitialState: () => DeepReadonly; } /** * Options for `createSlice()`. * * @public */ export interface CreateSliceOptions = SliceCaseReducers, Name extends string = string> { name: Name; initialState: State | (() => State); reducers: ValidateSliceCaseReducers; extraReducers?: CaseReducers, any> | ((builder: ActionReducerMapBuilder>) => void); } /** * A CaseReducer with a `prepare` method. * * @public */ export type CaseReducerWithPrepare = { reducer: CaseReducer; prepare: PrepareAction; }; /** * The type describing a slice's `reducers` option. * * @public */ export type SliceCaseReducers = { [K: string]: CaseReducer, PayloadAction> | CaseReducerWithPrepare, PayloadAction>; }; /** * Derives the slice's `actions` property from the `reducers` options * * @public */ export type CaseReducerActions> = { [Type in keyof CaseReducers]: CaseReducers[Type] extends { prepare: any; } ? ActionCreatorForCaseReducerWithPrepare : ActionCreatorForCaseReducer; }; /** * Get a `PayloadActionCreator` type for a passed `CaseReducerWithPrepare` * * @internal */ type ActionCreatorForCaseReducerWithPrepare = _ActionCreatorWithPreparedPayload; /** * Get a `PayloadActionCreator` type for a passed `CaseReducer` * * @internal */ type ActionCreatorForCaseReducer = CR extends (state: any, action: infer Action) => any ? Action extends { payload: infer P; } ? PayloadActionCreator

: ActionCreatorWithoutPayload : ActionCreatorWithoutPayload; /** * Extracts the CaseReducers out of a `reducers` object, even if they are * tested into a `CaseReducerWithPrepare`. * * @internal */ type SliceDefinedCaseReducers> = { [Type in keyof CaseReducers]: CaseReducers[Type] extends { reducer: infer Reducer; } ? Reducer : CaseReducers[Type]; }; /** * Used on a SliceCaseReducers object. * Ensures that if a CaseReducer is a `CaseReducerWithPrepare`, that * the `reducer` and the `prepare` function use the same type of `payload`. * * Might do additional such checks in the future. * * This type is only ever useful if you want to write your own wrapper around * `createSlice`. Please don't use it otherwise! * * @public */ export type ValidateSliceCaseReducers> = ACR & { [T in keyof ACR]: ACR[T] extends { reducer(s: S, action?: infer A): any; } ? { prepare(...a: never[]): Omit; } : {}; }; /** * A function that accepts an initial state, an object full of reducer * functions, and a "slice name", and automatically generates * action creators and action types that correspond to the * reducers and state. * * The `reducer` argument is passed to `createReducer()`. * * @public */ export declare function createSlice, Name extends string = string>(options: CreateSliceOptions): Slice; export {}; //# sourceMappingURL=createSlice.d.ts.map