Skip to content

Commit 0a93474

Browse files
brenelzclaude
andcommitted
fix: keep partial seeds while allowing readonly store seeds
Match createStore's projection seed type (Partial<T> | Store<NoFn<T>>) instead of NoFn<T> | Store<NoFn<T>>, which rejected the documented partial-seed pattern. Align the server createProjection signature and add type tests for store-as-seed inference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a229d67 commit 0a93474

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

packages/solid-signals/src/store/projection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function createProjectionInternal<T extends object = {}>(
108108
*/
109109
export function createProjection<T extends object = {}>(
110110
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
111-
seed: NoFn<T> | Store<NoFn<T>>,
111+
seed: Partial<T> | Store<NoFn<T>>,
112112
options?: ProjectionOptions
113113
): Refreshable<Store<T>> {
114114
return createProjectionInternal(fn, seed, options).store;

packages/solid-signals/tests/store/store.type-tests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ import {
9898
store[0].name satisfies string;
9999
}
100100

101+
// ── createProjection — store as seed ──────────────────────────────────
102+
103+
{
104+
const [todos] = createStore([] as { id: number; done: boolean }[]);
105+
const proj = createProjection(() => todos.filter(t => !t.done), todos);
106+
proj[0].id satisfies number;
107+
proj[0].done satisfies boolean;
108+
}
109+
110+
{
111+
const [state] = createStore({ count: 0 });
112+
const proj = createProjection(() => ({ count: 1 }), state);
113+
proj.count satisfies number;
114+
}
115+
101116
// ── createOptimisticStore (projection) — partial seed ─────────────────
102117

103118
{

packages/solid/src/client/hydration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ export const createOptimistic: {
10171017
*/
10181018
export const createProjection: <T extends object = {}>(
10191019
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
1020-
initialValue: NoFn<T> | Store<NoFn<T>>,
1020+
initialValue: Partial<T> | Store<NoFn<T>>,
10211021
options?: ProjectionOptions
10221022
) => Refreshable<Store<T>> = ((...args: any[]) =>
10231023
(_createProjection || coreProjection)(...args)) as any;

packages/solid/src/server/signals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ function createPendingProxy<T extends object>(
10561056

10571057
export function createProjection<T extends object>(
10581058
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
1059-
initialValue: Partial<T>,
1059+
initialValue: Partial<T> | Store<T>,
10601060
options?: ServerSsrOptions
10611061
): Store<T> {
10621062
const ctx = sharedConfig.context;

0 commit comments

Comments
 (0)