Skip to content

Commit

Permalink
revert: feat: enforce deep readonly state
Browse files Browse the repository at this point in the history
Reverts commit e64b897 because forcing deeply-readonly types can cause various breaking issues with incompatible types.

Whether state is read-only should be up to the user.
  • Loading branch information
littensy committed Jun 26, 2023
1 parent 2610cac commit 5f285c5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ export declare const loggerMiddleware: ProducerMiddleware;
* be used to modify the state. The state is immmutable, so dispatchers return
* a new state object.
*/
export type Producer<State = any, Actions = any> = ProducerDispatchers<State, Actions> &
ProducerImpl<DeepReadonly<State>, Actions>;
export type Producer<State = any, Actions = any> = ProducerDispatchers<State, Actions> & ProducerImpl<State, Actions>;

/**
* An implementation of the Producer interface. This is used internally and
Expand Down Expand Up @@ -399,7 +398,7 @@ export type InferDispatchers<T> = T extends Producer<infer State, infer Actions>
* @template State The state type of the producer.
*/
export interface ProducerActions<State> {
readonly [name: string]: (state: DeepReadonly<State>, ...args: any[]) => DeepReadonly<State>;
readonly [name: string]: (state: State, ...args: any[]) => State;
}

/**
Expand All @@ -410,7 +409,7 @@ export interface ProducerActions<State> {
*/
export type ProducerDispatchers<State, Actions> = {
readonly [K in keyof Actions]: Actions[K] extends (state: State, ...args: infer Args) => State
? (...args: Args) => DeepReadonly<State>
? (...args: Args) => State
: never;
};

Expand Down

0 comments on commit 5f285c5

Please sign in to comment.