Skip to content

fix(storage): restore makePersisted type inference for input signal - #1064

Open
wahajahmed010 wants to merge 1 commit into
solidjs-community:mainfrom
wahajahmed010:fix/1000-makepersisted-type-inference
Open

wahajahmed010 wants to merge 1 commit into
solidjs-community:mainfrom
wahajahmed010:fix/1000-makepersisted-type-inference

Conversation

@wahajahmed010

@wahajahmed010 wahajahmed010 commented Sep 23, 2026 •

Copy link
Copy Markdown

Fixes #1000.

The 4.4.0 release rewrote the public makePersisted overloads to <T, S extends Signal<T> | [Store<T>, SetStoreFunction<T>]>, relying on TypeScript to infer T from S. Under stricter inference (TypeScript 5/7) that no longer happens reliably, so T falls back to unknown and the call site errors with TS2769 (No overload matches this call). Users had to fall back to explicit type arguments like makePersisted<string, Signal<string>>(...).

This change restores the 4.3.5 shape:

  • A SignalInput / SignalType<S> helper pair is reintroduced so the public overloads only take <S>. T is extracted via SignalType<S> in the PersistenceOptions<T, ...> argument, which is the standard pattern for inferring the inner type of a signal/store tuple.
  • The implementation signature keeps T = SignalType<S> as a defaulted type parameter, so the body and internal call sites are unchanged.
  • Adds a regression test (infers the signal value type from the input without explicit annotations) that fails on the previous overloads and passes here. Running it against the old source with tsc --strict reproduces the original TS2769 error verbatim.

No runtime changes — pure type-level fix. The full vitest suite for @solid-primitives/storage (21 tests across 4 files) passes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed TypeScript type inference for makePersisted, so signal values retain their expected types instead of being inferred as unknown.
    • Improved support for calling makePersisted without storage options when no options are required.

The 4.4.0 release rewrote the public makePersisted overloads to take
<T, S extends Signal<T> | [Store<T>, SetStoreFunction<T>]>, expecting
TypeScript to infer T from S. Under stricter inference (TS 5/7) that
no longer happens reliably: T falls back to unknown, so calls like

  makePersisted(createSignal('hello'), { name, storage: localStorage })

fail with TS2769 ("No overload matches this call"). Users had to add
explicit type arguments as a workaround.

Restore the 4.3.5 shape: public overloads only take <S>, with
SignalType<S> extracting T. The implementation signature keeps a
defaulted T = SignalType<S> so internal callers and the body still
compile. Add a regression test that fails on the old overloads and
passes here.

Closes solidjs-community#1000

Signed-off-by: Wahaj Ahmed <wahaj.ahmed010@gmail.com>
@changeset-bot

changeset-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb1b61e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solid-primitives/storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c6aec871-f005-492c-bf01-6f61da6b9c2e

📥 Commits

Reviewing files that changed from the base of the PR and between c7b608c and cb1b61e.

📒 Files selected for processing (3)
  • .changeset/makepersisted-type-inference-fix.md
  • packages/storage/src/persisted.ts
  • packages/storage/test/persisted.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

makePersisted now derives its value type from the supplied signal or store pair. Its overloads also allow options to be omitted when no storage-options type applies. A regression test checks string inference and signal updates.

Changes

Persisted signal type inference

Layer / File(s) Summary
Signal type inference and validation
packages/storage/src/persisted.ts, packages/storage/test/persisted.test.ts, .changeset/makepersisted-type-inference-fix.md
SignalInput and SignalType describe accepted signal shapes and extract their value type. makePersisted overloads use this extracted type and allow omitted options when no storage-options type applies. A regression test checks inferred string types and updates; a patch changeset records the fix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to cb1b6

The inference fix is mergeable after normal checks; no outstanding risk is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: restoring type inference for the makePersisted input signal in the storage package.
Linked Issues check ✅ Passed Issue #1000 requires makePersisted(createSignal("hello"), ...) to infer the signal value type without explicit type arguments. The PR changes the public overloads to derive the value type with `Sign…
Out of Scope Changes check ✅ Passed The changes stay within issue #1000. The type aliases and overload updates implement the requested inference fix. The regression test verifies the requested behavior. The changeset documents the fix. …
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

makePersisted() cannot correctly infer types under Typescript 7

1 participant