Skip to content
Closed
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
32 changes: 32 additions & 0 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,10 +2148,42 @@ declare module 'svelte/store' {
*/
update(this: void, updater: Updater<T>): void;
}

/**
* Create a store from a function that returns state, and (to make a writable store), an
* optional second function that sets state.
*
* ```ts
* import { toStore } from 'svelte/store';
*
* let count = $state(0);
*
* const store = toStore(() => count, (v) => (count = v));
* ```
*/
export function toStore<V>(get: () => V, set: (v: V) => void): Writable<V>;

export function toStore<V>(get: () => V): Readable<V>;

/**
* Convert a store to an object with a reactive `current` property. If `store`
* is a readable store, `current` will be a readonly property.
*
* ```ts
* import { fromStore, get, writable } from 'svelte/store';
*
* const store = writable(0);
*
* const count = fromStore(store);
*
* count.current; // 0;
* store.set(1);
* count.current; // 1
*
* count.current += 1;
* get(store); // 2
* ```
*/
export function fromStore<V>(store: Writable<V>): {
current: V;
};
Expand Down
Loading