Skip to content

Commit 6db369a

Browse files
committed
Make storePart argument optional in overloads
1 parent 06379a3 commit 6db369a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/interactivity/src/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ export function store< T extends object >(
179179
// Overload for when types are passed via generics and they contain state.
180180
export function store< T extends { state: object } >(
181181
namespace: string,
182-
storePart: ConvertPromisesToGenerators< DeepPartialState< T > >,
182+
storePart?: ConvertPromisesToGenerators< DeepPartialState< T > >,
183183
options?: StoreOptions
184184
): Prettify< ConvertGeneratorsToPromises< T > >;
185185

186186
// Overload for when types are passed via generics and they don't contain state.
187187
export function store< T extends object >(
188188
namespace: string,
189-
storePart: ConvertPromisesToGenerators< T >,
189+
storePart?: ConvertPromisesToGenerators< T >,
190190
options?: StoreOptions
191191
): Prettify< ConvertGeneratorsToPromises< T > >;
192192

packages/interactivity/src/test/store.ts

+23
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,29 @@ describe( 'Interactivity API', () => {
281281
myStore.state.nonExistent satisfies {};
282282
};
283283
} );
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+
} );
284307
} );
285308
} );
286309
} );

0 commit comments

Comments
 (0)