Skip to content

Commit

Permalink
fix(core): fixed mutation typing for unknown payload type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Feb 11, 2021
1 parent e9fb5b6 commit 438459a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions core/src/internal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Store<T extends object = any> implements InternalStore<T> {
return output;
};

private mutate<U>(name: string, sender: string, mutator: Mutator<T, U>, payload?: U): void {
private mutate<U>(name: string, sender: string, mutator: Mutator<T, U>, payload: U): void {
const eventData: MutationEventData = {
payload,
mutation: name
Expand All @@ -114,11 +114,11 @@ export default class Store<T extends object = any> implements InternalStore<T> {

this.mutations.add(name);

return (payload?: U) => this.mutate(name, SENDER, mutator, payload);
return ((payload: U) => this.mutate(name, SENDER, mutator, payload)) as Mutation<U>;
}

public exec(name: string, sender: string, mutator: Mutator<T, undefined>): void {
this.mutate(name, sender, mutator);
this.mutate(name, sender, mutator, undefined);
}

}
4 changes: 2 additions & 2 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
export type ReadState<T> = DeepReadonly<T>;
export type WriteState<T> = UnwrapRef<T>;
export type Getter<T, U> = (state: ReadState<T>) => U;
export type Mutator<T, U> = (state: WriteState<T>, payload?: U) => void;
export type Mutation<T> = (payload?: T) => void;
export type Mutator<T, U> = (state: WriteState<T>, payload: U) => void;
export type Mutation<T> = undefined extends T ? (payload?: T) => void : (payload: T) => void;
export type InternalStores = Map<string, InternalStore<any>>;
export type EventHandler<T = any> = (payload?: EventPayload<T>) => void;

Expand Down

1 comment on commit 438459a

@vercel
Copy link

@vercel vercel bot commented on 438459a Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.