@@ -122,16 +122,30 @@ type StoresValues<T> = T extends Readable<infer U> ? U :
122
122
/**
123
123
* Derived value store by synchronizing one or more readable stores and
124
124
* applying an aggregation function over its input values.
125
- * @param { Stores } stores input stores
126
- * @param { function(Stores=, function(*)=):* }fn function callback that aggregates the values
127
- * @param { *= }initial_value when used asynchronously
125
+ *
126
+ * @param stores - input stores
127
+ * @param fn - function callback that aggregates the values
128
128
*/
129
- export function derived < T , S extends Stores > (
129
+ export function derived < S extends Stores , T > (
130
130
stores : S ,
131
- fn : ( values : StoresValues < S > , set : Subscriber < T > ) => T | Unsubscriber | void ,
132
- initial_value ?: T ,
133
- ) : Readable < T > {
131
+ fn : ( values : StoresValues < S > ) => T
132
+ ) : Readable < T > ;
134
133
134
+ /**
135
+ * Derived value store by synchronizing one or more readable stores and
136
+ * applying an aggregation function over its input values.
137
+ *
138
+ * @param stores - input stores
139
+ * @param fn - function callback that aggregates the values
140
+ * @param initial_value - when used asynchronously
141
+ */
142
+ export function derived < S extends Stores , T > (
143
+ stores : S ,
144
+ fn : ( values : StoresValues < S > , set : ( value : T ) => void ) => Unsubscriber | void ,
145
+ initial_value ?: T
146
+ ) : Readable < T > ;
147
+
148
+ export function derived < T > ( stores : Stores , fn : Function , initial_value ?: T ) : Readable < T > {
135
149
const single = ! Array . isArray ( stores ) ;
136
150
const stores_array : Array < Readable < any > > = single
137
151
? [ stores as Readable < any > ]
@@ -141,7 +155,7 @@ export function derived<T, S extends Stores>(
141
155
142
156
return readable ( initial_value , ( set ) => {
143
157
let inited = false ;
144
- const values : StoresValues < S > = [ ] as StoresValues < S > ;
158
+ const values = [ ] ;
145
159
146
160
let pending = 0 ;
147
161
let cleanup = noop ;
0 commit comments