File tree 2 files changed +38
-2
lines changed
packages/interactivity/src
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -179,14 +179,14 @@ export function store< T extends object >(
179
179
// Overload for when types are passed via generics and they contain state.
180
180
export function store < T extends { state : object } > (
181
181
namespace : string ,
182
- storePart : ConvertPromisesToGenerators < DeepPartialState < T > > ,
182
+ storePart ? : ConvertPromisesToGenerators < DeepPartialState < T > > ,
183
183
options ?: StoreOptions
184
184
) : Prettify < ConvertGeneratorsToPromises < T > > ;
185
185
186
186
// Overload for when types are passed via generics and they don't contain state.
187
187
export function store < T extends object > (
188
188
namespace : string ,
189
- storePart : ConvertPromisesToGenerators < T > ,
189
+ storePart ? : ConvertPromisesToGenerators < T > ,
190
190
options ?: StoreOptions
191
191
) : Prettify < ConvertGeneratorsToPromises < T > > ;
192
192
Original file line number Diff line number Diff line change @@ -281,6 +281,42 @@ describe( 'Interactivity API', () => {
281
281
myStore . state . nonExistent satisfies { } ;
282
282
} ;
283
283
} ) ;
284
+
285
+ describe ( 'a typed store can be returned without adding a new store part' , ( ) => {
286
+ type State = {
287
+ someValue : number ;
288
+ } ;
289
+ type Actions = {
290
+ incrementValue : ( n : number ) => void ;
291
+ } ;
292
+
293
+ const { state, actions } = store < {
294
+ state : State ;
295
+ actions : Actions ;
296
+ } > ( 'storeWithState' , {
297
+ actions : {
298
+ incrementValue ( n ) {
299
+ state . someValue += n ;
300
+ } ,
301
+ } ,
302
+ } ) ;
303
+
304
+ state . someValue satisfies number ;
305
+ actions . incrementValue ( 1 ) satisfies void ;
306
+
307
+ const { actions : actions2 } = store < { actions : Actions } > (
308
+ 'storeWithoutState' ,
309
+ {
310
+ actions : {
311
+ incrementValue ( n ) {
312
+ state . someValue += n ;
313
+ } ,
314
+ } ,
315
+ }
316
+ ) ;
317
+
318
+ actions2 . incrementValue ( 1 ) satisfies void ;
319
+ } ) ;
284
320
} ) ;
285
321
} ) ;
286
322
} ) ;
You can’t perform that action at this time.
0 commit comments