diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index afd4ccabd61e..51a13b85e21f 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -13,7 +13,7 @@ export type Updater = (value: T) => T; type Invalidator = (value?: T) => void; /** Start and stop notification callbacks. */ -export type StartStopNotifier = (set: Subscriber, update?: (fn: Updater) => void) => Unsubscriber | void; +export type StartStopNotifier = (set: Subscriber, update: (fn: Updater) => void) => Unsubscriber | void; /** Readable interface for subscribing. */ export interface Readable { @@ -115,6 +115,20 @@ type Stores = Readable | [Readable, ...Array>] | Array = T extends Readable ? U : { [K in keyof T]: T[K] extends Readable ? U : never }; +/** + * Derived value store by synchronizing one or more readable stores and + * applying an aggregation function over its input values. + * + * @param stores - input stores + * @param fn - function callback that aggregates the values + * @param initial_value - when used asynchronously + */ + export function derived( + stores: S, + fn: (values: StoresValues, set: Subscriber, update: (fn: Updater) => void) => Unsubscriber | void, + initial_value?: T +): Readable; + /** * Derived value store by synchronizing one or more readable stores and * applying an aggregation function over its input values. @@ -125,7 +139,7 @@ type StoresValues = T extends Readable ? U : */ export function derived( stores: S, - fn: (values: StoresValues, set: Subscriber, update?: (fn: Updater) => void) => Unsubscriber | void, + fn: (values: StoresValues, set: Subscriber) => Unsubscriber | void, initial_value?: T ): Readable;