File tree 2 files changed +25
-2
lines changed
packages/interactivity/src
2 files changed +25
-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,29 @@ 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
+
298
+ state . someValue satisfies number ;
299
+ actions . incrementValue ( 1 ) satisfies void ;
300
+
301
+ const { actions : actions2 } = store < { actions : Actions } > (
302
+ 'storeWithoutState'
303
+ ) ;
304
+
305
+ actions2 . incrementValue ( 1 ) satisfies void ;
306
+ } ) ;
284
307
} ) ;
285
308
} ) ;
286
309
} ) ;
You can’t perform that action at this time.
0 commit comments