Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StoreBundle<T> type #2363

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/solid/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type {
SetStoreFunction,
SolidStore,
Store,
StoreBundle,
StoreNode,
StorePathRange,
StoreSetter
Expand Down
4 changes: 3 additions & 1 deletion packages/solid/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ export interface SetStoreFunction<T> {
): void;
}

export type StoreBundle<T> = [get: Store<T>, set: SetStoreFunction<T>];

/**
* Creates a reactive store that can be read through a proxy object and written with a setter function
*
Expand All @@ -499,7 +501,7 @@ export function createStore<T extends object = {}>(
...[store, options]: {} extends T
? [store?: T | Store<T>, options?: { name?: string }]
: [store: T | Store<T>, options?: { name?: string }]
): [get: Store<T>, set: SetStoreFunction<T>] {
): StoreBundle<T> {
const unwrappedStore = unwrap((store || {}) as T);
const isArray = Array.isArray(unwrappedStore);
if ("_SOLID_DEV_" && typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
Expand Down