Skip to content

Commit

Permalink
fix(core): fixed typing for extension options
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Nov 18, 2022
1 parent f692da0 commit ef05d38
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function installPlugin(plugin: HarlemPlugin, app: App): void {
export const on = eventEmitter.on.bind(eventEmitter);
export const once = eventEmitter.once.bind(eventEmitter);

export function createStore<TState extends BaseState, TExtensions extends Extension<TState>[] = []>(
export function createStore<TState extends BaseState, TExtensions extends Extension<TState>[]>(
name: string,
state: TState,
options?: Partial<StoreOptions<TState, TExtensions>>
Expand All @@ -132,7 +132,7 @@ export function createStore<TState extends BaseState, TExtensions extends Extens
extensions,
} = {
allowOverwrite: true,
extensions: [store => ({})] as TExtensions,
extensions: [] as unknown as TExtensions,
...options,
};

Expand Down
4 changes: 2 additions & 2 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Trigger<TEventData extends TriggerEventData> = (matcher: Matcher | M
export type BranchAccessor<TState extends BaseState, TValue> = (state: ReadState<TState>) => TValue;
export type InternalStores = Map<string, InternalStore<BaseState>>;
export type Extension<TState extends BaseState> = (store: InternalStore<TState>) => Record<string, any>;
export type ExtensionAPIs<TExtensions extends Extension<BaseState>[]> = UnionToIntersection<ReturnType<TExtensions[number]>>;
export type ExtensionAPIs<TExtensions extends Extension<BaseState>[]> = Record<string, any> extends UnionToIntersection<ReturnType<TExtensions[number]>> ? unknown : UnionToIntersection<ReturnType<TExtensions[number]>>;
export type PublicStore<TState extends BaseState, TExtensions extends Extension<TState>[]> = Omit<Store<TState>, keyof ExtensionAPIs<TExtensions>> & ExtensionAPIs<TExtensions>;

export interface Emittable {
Expand Down Expand Up @@ -68,7 +68,7 @@ export interface StoreRegistration {

export interface StoreSnapshot<TState extends BaseState> {
get state(): TState;
apply<TValue>(branchCallback?: BranchAccessor<TState, TValue>, mutationName?: string): void;
apply<TValue>(branchAccessor?: BranchAccessor<TState, TValue>, mutationName?: string): void;
}

export interface StoreBase<TState extends BaseState> {
Expand Down

0 comments on commit ef05d38

Please sign in to comment.