Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/fix-create-projection-seed-inference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@solidjs/signals": patch
"solid-js": patch
---

Fix `createProjection` seed typing so readonly store seeds do not override inference from the projection function return type.
3 changes: 2 additions & 1 deletion packages/solid-signals/src/store/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
STORE_WRAP,
storeSetter,
storeTraps,
type NoFn,
type ProjectionOptions,
type Store
} from "./store.js";
Expand Down Expand Up @@ -107,7 +108,7 @@ export function createProjectionInternal<T extends object = {}>(
*/
export function createProjection<T extends object = {}>(
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
seed: Partial<T>,
seed: Partial<T> | Store<NoFn<T>>,
options?: ProjectionOptions
): Refreshable<Store<T>> {
return createProjectionInternal(fn, seed, options).store;
Expand Down
15 changes: 15 additions & 0 deletions packages/solid-signals/tests/store/store.type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ import {
store[0].name satisfies string;
}

// ── createProjection — store as seed ──────────────────────────────────

{
const [todos] = createStore([] as { id: number; done: boolean }[]);
const proj = createProjection(() => todos.filter(t => !t.done), todos);
proj[0].id satisfies number;
proj[0].done satisfies boolean;
}

{
const [state] = createStore({ count: 0 });
const proj = createProjection(() => ({ count: 1 }), state);
proj.count satisfies number;
}

// ── createOptimisticStore (projection) — partial seed ─────────────────

{
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/src/client/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ export const createOptimistic: {
*/
export const createProjection: <T extends object = {}>(
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
initialValue: T,
initialValue: Partial<T> | Store<NoFn<T>>,
options?: ProjectionOptions
) => Refreshable<Store<T>> = ((...args: any[]) =>
(_createProjection || coreProjection)(...args)) as any;
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/src/server/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ function createPendingProxy<T extends object>(

export function createProjection<T extends object>(
fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>,
initialValue: Partial<T>,
initialValue: Partial<T> | Store<T>,
options?: ServerSsrOptions
): Store<T> {
const ctx = sharedConfig.context;
Expand Down
Loading