@@ -13,7 +13,7 @@ export type Updater<T> = (value: T) => T;
13
13
type Invalidator < T > = ( value ?: T ) => void ;
14
14
15
15
/** Start and stop notification callbacks. */
16
- export type StartStopNotifier < T > = ( set : Subscriber < T > , update ? : ( fn : Updater < T > ) => void ) => Unsubscriber | void ;
16
+ export type StartStopNotifier < T > = ( set : Subscriber < T > , update : ( fn : Updater < T > ) => void ) => Unsubscriber | void ;
17
17
18
18
/** Readable interface for subscribing. */
19
19
export interface Readable < T > {
@@ -115,6 +115,20 @@ type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<R
115
115
type StoresValues < T > = T extends Readable < infer U > ? U :
116
116
{ [ K in keyof T ] : T [ K ] extends Readable < infer U > ? U : never } ;
117
117
118
+ /**
119
+ * Derived value store by synchronizing one or more readable stores and
120
+ * applying an aggregation function over its input values.
121
+ *
122
+ * @param stores - input stores
123
+ * @param fn - function callback that aggregates the values
124
+ * @param initial_value - when used asynchronously
125
+ */
126
+ export function derived < S extends Stores , T > (
127
+ stores : S ,
128
+ fn : ( values : StoresValues < S > , set : Subscriber < T > , update : ( fn : Updater < T > ) => void ) => Unsubscriber | void ,
129
+ initial_value ?: T
130
+ ) : Readable < T > ;
131
+
118
132
/**
119
133
* Derived value store by synchronizing one or more readable stores and
120
134
* applying an aggregation function over its input values.
@@ -125,7 +139,7 @@ type StoresValues<T> = T extends Readable<infer U> ? U :
125
139
*/
126
140
export function derived < S extends Stores , T > (
127
141
stores : S ,
128
- fn : ( values : StoresValues < S > , set : Subscriber < T > , update ?: ( fn : Updater < T > ) => void ) => Unsubscriber | void ,
142
+ fn : ( values : StoresValues < S > , set : Subscriber < T > ) => Unsubscriber | void ,
129
143
initial_value ?: T
130
144
) : Readable < T > ;
131
145
0 commit comments