Support input signals in Angular adapter #291
main fromrefs/pull/291/head·opened 🎯 Changes#
- Adds support to input signals by allowing the first argument to be a function that returns the store
- Correctly supports selectors with input signals by running the selector only in effects and linkedSignal.
- Migrates angular tests to use testing library, like the other adapters
A full write out can be found here.
The main idea is that in Angular we can't call input signals on component initialization, so this fails:
export function injectRelativeTimestamp(timestamp: Signal<number>) {
// Throws NG0952/NG0950: no model/input available yet
const relativeTimestamp = new RelativeTime(timestamp());
}
By allowing a function/signal, we can allow consumers to lazy initialize the store, demonstrated by a couple of tests where createStableSignal (computed(() => untracked(fn))) is used. A previous PR I made #285 added that helper in the library, but since in React we are using useState or useRef without a helper to do the same idea (keeping a stable reference to the store), this PR does not provide a similar helper. Consumers are expected to keep the store getter function/signal stable.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
New Features
- Atoms, selectors and stores can be provided lazily via factory functions.
- Store injection now returns a callable signal-like slice that combines value access with actions (or setState).
Documentation
- Updated signatures and examples to reflect lazy inputs and the callable slice API.
Tests / Tooling
- Tests migrated to Angular signal APIs and centralized test runner; typings and test cases updated.
Examples
- Example app wiring adjusted to use the new callable slice.
Chores
- Test config and dev tooling dependencies updated.
- 1
View your CI Pipeline Execution ↗ for commit 38ccc0b7b17162a488e1ce9ce033cca8e1608b30
☁️ Nx Cloud last updated this comment at
2026-03-12 18:57:06UTC📝 Walkthrough
Walkthrough#
This PR accepts lazy factory inputs across injectAtom/injectSelector/_injectStore, changes _injectStore to return a callable proxy signal exposing actions or setState, rewrites selector subscription to use Angular effects, updates docs/examples, and migrates tests to an AnalogJS Vitest Angular testbed.
Changes#
Angular store changes
Layer / File(s) Summary Changeset entry
.changeset/eight-ways-dig.mdAdded patch changeset documenting support for input signals. Docs: updated signatures
docs/framework/angular/reference/functions/injectAtom.md,docs/framework/angular/reference/functions/injectSelector.md,docs/framework/angular/reference/functions/injectStore.mdDocumentation signatures expanded to accept factory forms (e.g., `Atom _injectStore: callable slice
packages/angular-store/src/_injectStore.tsAdded WritableStoreSliceSignaltype;_injectStorenow accepts lazystoreand returns a callable Proxy that reads selected value and forwards properties to store actions orsetState.injectAtom: lazy setter
packages/angular-store/src/injectAtom.tsinjectAtomaccepts `AtominjectSelector: effect-based subscription
packages/angular-store/src/injectSelector.tsinjectSelectoraccepts thunk-or-source, uses Angulareffectto subscribe/teardown, and sets equality only fromoptions?.compare.Example app
examples/angular/store-actions/src/app/app.component.tsUpdated example to use callable slice API ( dogs.addDog()), removed tuple destructuring and separate action fields.Package config
packages/angular-store/package.jsonUpdated devDependencies: removed @angular/platform-browser-dynamic; added@analogjs/vitest-angular,@testing-library/angular,@testing-library/jest-dom.Tests & testbed / config
packages/angular-store/tests/*,packages/angular-store/tsconfig.spec.json,packages/angular-store/vitest.config.tsSwitched test setup to @analogjs/vitest-angularsetupTestBed(); added tests for lazy atom/selector inputs and callable slice behavior; updated type tests to assert `Signal & { actionsSequence Diagram(s)#
sequenceDiagram participant Component participant SliceProxy participant StoreInstance participant Actions Component->>SliceProxy: call slice() (read selected value) SliceProxy->>StoreInstance: resolve lazy store (untracked) / read selected signal StoreInstance-->>SliceProxy: selected value SliceProxy-->>Component: return value Component->>SliceProxy: call slice.someAction(...) (e.g., addDog) SliceProxy->>Actions: forward to store.actions.someAction Actions-->>StoreInstance: mutate state StoreInstance-->>SliceProxy: selected signal updates SliceProxy-->>Component: new value on subsequent slice() callsEstimated code review effort#
🎯 4 (Complex) | ⏱️ ~50 minutes
Poem#
🐰 I nibbled code and found a cozy way to play, Factories hum softly, signals hop and sway, A proxy learned to answer when the slice was called, Actions and setState now rest where they belong, installed, Tests tucked in a new bed—how bright the harvest day!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold. ✏️ Tip: You can configure your own custom pre-merge checks in the settings.✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title 'Support input signals in Angular adapter' directly and clearly summarizes the main objective of the PR—adding support for input signals to the Angular store adapter, which is the primary feature being introduced. Description check ✅ Passed The PR description fully addresses the template requirements with a comprehensive Changes section explaining the feature and its motivation, both checklist items properly checked, and the Release Impact section indicating a changeset was generated for published code changes. Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Warning
There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
ESLint install failed: lockfile failed supply-chain policy check. Run
pnpm installlocally to update the lockfile.
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.
Comment `@coderabbitai help` to get the list of available commands and usage tips.Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/angular-store/tests/index.test.ts (1)
133-159: Clarify thecreateStableSignal+effectpattern with a comment.The atom is created exactly once from the initial input value (due to
untrackedincreateStableSignal), and subsequent updates are propagated through the expliciteffectthat callsthis.doubled.set(...). This is subtle and the exact pattern consumers are expected to follow per the PR notes — a one-line comment in the test would help future readers understand why both pieces are needed (and why simply readingthis.value()insidecreateAtom(...)would not react).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/angular-store/tests/index.test.ts` around lines 133 - 159, Add a one-line comment in the test above AtomFromInputChildCmp explaining that createStableSignal/untracked ensures the createAtom call runs only once (so the atom is created from the initial input value), and that the separate effect calling this.doubled.set(this.value() * 2) is required to propagate subsequent input changes to the injected atom (i.e. why reading this.value() inside createAtom would not make it reactive). Reference the createStableSignal, createAtom, injectAtom, and effect usage to make the intent clear to future readers.docs/framework/angular/reference/functions/injectStore.md (1)
12-65: Docs accurately reflect the newWritableStoreSliceSignalreturn.One small suggestion: mention in the "Returns" section that the result is also a
Signal<TSelected>(callable) so readers immediately grasp the dual nature, rather than only seeing it in the example. Optional.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/framework/angular/reference/functions/injectStore.md` around lines 12 - 65, Update the "Returns" section for _injectStore/WritableStoreSliceSignal to explicitly state the return value is also a callable Signal<TSelected> (i.e., it behaves as Signal<TSelected> and exposes writable slice methods or setState depending on the store), so readers see the dual nature immediately; mention the generic form WritableStoreSliceSignal<TState, TSelected, TActions> is also a Signal<TSelected> and is callable (e.g., value()) in addition to its methods.🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Inline comments: In `@packages/angular-store/src/injectSelector.ts`: - Around line 73-78: The effect currently returns the unsubscribe function which Angular's effect ignores, leaking subscriptions; change the effect callback to accept the onCleanup parameter and use it to tear down the subscription: when calling _source().subscribe(...) keep the Subscription (or its unsubscribe method) and call onCleanup(() => subscription.unsubscribe()) so each re-run and injector destruction properly unsubscribes and prevents multiple slice.set calls from stale subscriptions. In `@packages/angular-store/tests/index.test.ts`: - Around line 560-564: Change the member visibility of value from private to protected so the template can access it consistently with the sibling test; locate the class that defines "private value = _injectStore(store, (state) => state)" and update the declaration to "protected value" (keep the rest of the code, including the inc() method and the use of _injectStore, unchanged). In `@packages/angular-store/tsconfig.spec.json`: - Line 7: The tsconfig.spec.json currently lists a non-existent setup path ("src/test-setup.ts"); update the "files" entry in tsconfig.spec.json to point to the actual test setup file ("tests/test-setup.ts") so TypeScript typechecking uses the same setup used by vitest (setupFiles: ['./tests/test-setup.ts']). Locate the "files" array in tsconfig.spec.json and replace "src/test-setup.ts" with "tests/test-setup.ts". --- Nitpick comments: In `@docs/framework/angular/reference/functions/injectStore.md`: - Around line 12-65: Update the "Returns" section for _injectStore/WritableStoreSliceSignal to explicitly state the return value is also a callable Signal<TSelected> (i.e., it behaves as Signal<TSelected> and exposes writable slice methods or setState depending on the store), so readers see the dual nature immediately; mention the generic form WritableStoreSliceSignal<TState, TSelected, TActions> is also a Signal<TSelected> and is callable (e.g., value()) in addition to its methods. In `@packages/angular-store/tests/index.test.ts`: - Around line 133-159: Add a one-line comment in the test above AtomFromInputChildCmp explaining that createStableSignal/untracked ensures the createAtom call runs only once (so the atom is created from the initial input value), and that the separate effect calling this.doubled.set(this.value() * 2) is required to propagate subsequent input changes to the injected atom (i.e. why reading this.value() inside createAtom would not make it reactive). Reference the createStableSignal, createAtom, injectAtom, and effect usage to make the intent clear to future readers.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
b1554c20-9661-44e0-bbe1-8aa133837652📥 Commits
Reviewing files that changed from the base of the PR and between 83e2978f627ec53616249b2bda1037749b18b6ab and f7603d5d522a52fc70f9855ddd8d38a92c4de33c.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (14)
.changeset/eight-ways-dig.mddocs/framework/angular/reference/functions/injectAtom.mddocs/framework/angular/reference/functions/injectSelector.mddocs/framework/angular/reference/functions/injectStore.mdexamples/angular/store-actions/src/app/app.component.tspackages/angular-store/package.jsonpackages/angular-store/src/_injectStore.tspackages/angular-store/src/injectAtom.tspackages/angular-store/src/injectSelector.tspackages/angular-store/tests/index.test.tspackages/angular-store/tests/test-setup.tspackages/angular-store/tests/test.test-d.tspackages/angular-store/tsconfig.spec.jsonpackages/angular-store/vitest.config.ts
packages/angular-store/src/injectSelector.ts lines 73 to 78OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -97,3 +59,20 @@9759 options?: InjectSelectorOptions<TSelected>,9860 ): Signal<TSelected> {99- return createReadonlySelectionSignal(source, selector, options)61+ const injector = resolveInjector(62+ injectSelector,63+ options?.injector,64+ )65+66+ return runInInjectionContext(injector, () => {67+ const _source = typeof source === "function" ? source : (() => source)68+69+ const slice = linkedSignal(() => selector(_source().get()), {70+ equal: options?.compare,71+ })72+73+ effect(() => {74+ const { unsubscribe } = _source().subscribe((state) => {75+ slice.set(selector(state))76+ })77+ return unsubscribe78+ })⚠️ Potential issue | 🔴 Critical
🧩 Analysis chain
🌐 Web query:
Does Angular effect() support returning a cleanup function, or must cleanup be registered via the onCleanup callback parameter?💡 Result:
Angular effect does not support returning a cleanup function. Cleanup must be registered via the onCleanup callback parameter, which is an optional first argument to the effect callback function of type EffectCleanupRegisterFn. This function is called before the next effect run or when the effect is destroyed, allowing registration of cleanup logic (e.g., clearTimeout). Official signature: effect(effectFn: (onCleanup: EffectCleanupRegisterFn) => void, options?: CreateEffectOptions): EffectRef Example from docs: effect((onCleanup) => { const timer = setTimeout( => { ... }, 1000); onCleanup( => clearTimeout(timer)); });
Citations:
Bug:
effectcleanup must use theonCleanupparameter, not a return value — this leaks subscriptions on every re-run.Angular's
effectAPI registers teardown via theonCleanupcallback passed to the effect function. The return value of the effect callback is ignored. As written, every time the effect re-runs (e.g., because an input signal that_source()depends on changes), a new subscription is created and the previous one is never unsubscribed. This produces:- Subscription leaks that grow with each input change.
- Multiple
slice.set(selector(state))calls per store emission (once per stale subscription). - No unsubscription when the injector is destroyed.
🔒 Proposed fix
- effect(() => { - const { unsubscribe } = _source().subscribe((state) => { - slice.set(selector(state)) - }) - return unsubscribe - }) + effect((onCleanup) => { + const { unsubscribe } = _source().subscribe((state) => { + slice.set(selector(state)) + }) + onCleanup(unsubscribe) + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/angular-store/src/injectSelector.ts` around lines 73 - 78, The effect currently returns the unsubscribe function which Angular's effect ignores, leaking subscriptions; change the effect callback to accept the onCleanup parameter and use it to tear down the subscription: when calling _source().subscribe(...) keep the Subscription (or its unsubscribe method) and call onCleanup(() => subscription.unsubscribe()) so each re-run and injector destruction properly unsubscribes and prevents multiple slice.set calls from stale subscriptions.✅ Addressed in commit 3abbb66
packages/angular-store/tests/index.test.ts lines 560 to 564OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -483,10 +557,8 @@483557 standalone: true,484558 })485559 class MyCmp {486- private result = _injectStore(store, (state) => state)487- value = this.result[0]488- setState = this.result[1]560+ private value = _injectStore(store, (state) => state)489561490562 inc() {491- this.setState((prev) => prev + 1)563+ this.value.setState((prev: number) => prev + 1)492564 }⚠️ Potential issue | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash # Check whether strictTemplates is enabled for the angular-store test project fd -a 'tsconfig*.json' packages/angular-store --exec sh -c 'echo "=== {} ==="; cat {}'Repository: TanStack/store
Length of output: 358
🏁 Script executed:
cat /home/jailuser/git/tsconfig.jsonRepository: TanStack/store
Length of output: 816
🏁 Script executed:
cd /home/jailuser/git && sed -n '510-570p' packages/angular-store/tests/index.test.tsRepository: TanStack/store
Length of output: 109
🏁 Script executed:
cd /home/jailuser/git && head -570 packages/angular-store/tests/index.test.ts | tail -70Repository: TanStack/store
Length of output: 1803
🏁 Script executed:
cd /home/jailuser/git && head -530 packages/angular-store/tests/index.test.ts | tail -20Repository: TanStack/store
Length of output: 460
🏁 Script executed:
find /home/jailuser/git -name 'angular.json' -o -name '.angular-cli.json'Repository: TanStack/store
Length of output: 350
🏁 Script executed:
cd /home/jailuser/git && grep -r "strictTemplates" packages/angular-store --include="*.json" --include="*.ts" --include="*.js"Repository: TanStack/store
Length of output: 40
🏁 Script executed:
cd /home/jailuser/git && cat packages/angular-store/vitest.config.tsRepository: TanStack/store
Length of output: 570
🏁 Script executed:
cd /home/jailuser/git && find packages/angular-store -name 'tsconfig*.json' -exec sh -c 'echo "=== {} ==="; cat {}' \;Repository: TanStack/store
Length of output: 929
Inconsistent member visibility vs. template access.
valueis declaredprivatebut is referenced from the template ({{ value() }}). The sibling test on line 523 correctly usesprotected countfor the same pattern. WhilestrictTemplatesis not currently enabled in the project's TypeScript configuration, align this toprotectedfor consistency with the same pattern elsewhere in the tests.Proposed change
- private value = _injectStore(store, (state) => state) + protected value = _injectStore(store, (state) => state)📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change560- private value = _injectStore(store, (state) => state)561-562- inc() {563- this.value.setState((prev: number) => prev + 1)564- }560+ protected value = _injectStore(store, (state) => state)561+562+ inc() {563+ this.value.setState((prev: number) => prev + 1)564+ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/angular-store/tests/index.test.ts` around lines 560 - 564, Change the member visibility of value from private to protected so the template can access it consistently with the sibling test; locate the class that defines "private value = _injectStore(store, (state) => state)" and update the declaration to "protected value" (keep the rest of the code, including the inc() method and the use of _injectStore, unchanged).✅ Addressed in commit 3abbb66
packages/angular-store/tsconfig.spec.json line 7OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,7 @@1+{2+ "extends": "./tsconfig.json",3+ "compilerOptions": {4+ "noEmit": false,5+ "types": ["vitest/globals", "node"]6+ },7+ "files": ["src/test-setup.ts"],⚠️ Potential issue | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash # Confirm the test-setup location and that src/test-setup.ts does not exist. fd -H -t f 'test-setup.ts' packages/angular-storeRepository: TanStack/store
Length of output: 100
🏁 Script executed:
cat packages/angular-store/tsconfig.spec.jsonRepository: TanStack/store
Length of output: 247
🏁 Script executed:
cat packages/angular-store/vitest.config.tsRepository: TanStack/store
Length of output: 570
Wrong path in
files:src/test-setup.tsdoes not exist — the actual setup file is attests/test-setup.ts.The setup file is located at
packages/angular-store/tests/test-setup.tsand is already wired up invitest.config.tsviasetupFiles: ['./tests/test-setup.ts']. Thetsconfig.spec.jsonpoints to a non-existentsrc/test-setup.ts, which will cause TypeScript to fail on typecheck.🔧 Proposed fix
- "files": ["src/test-setup.ts"], + "files": ["tests/test-setup.ts"], "include": ["tests/**/*.ts"]📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change7- "files": ["src/test-setup.ts"],7+ "files": ["tests/test-setup.ts"],8+ "include": ["tests/**/*.ts"]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/angular-store/tsconfig.spec.json` at line 7, The tsconfig.spec.json currently lists a non-existent setup path ("src/test-setup.ts"); update the "files" entry in tsconfig.spec.json to point to the actual test setup file ("tests/test-setup.ts") so TypeScript typechecking uses the same setup used by vitest (setupFiles: ['./tests/test-setup.ts']). Locate the "files" array in tsconfig.spec.json and replace "src/test-setup.ts" with "tests/test-setup.ts".✅ Addressed in commit 3abbb66
Updated the PR with the changes to the public api (from store -> to select selector and atom).
Also updated the experimental
injectStorewith a proxy pattern instead of the tuple pattern. The tuple pattern is undesirable in Angular since you can't destructure in a class body, and thanks to that, Angula's APIs don't use destructuring.🧹 Nitpick comments (1)
packages/angular-store/tests/index.test.ts (1)
500-506: Add_injectStorecoverage for lazy store factories.Current
_injectStoretests cover direct stores, but the PR’s new lazy-source contract also needs a proxy-path regression test, especially for.inc()/.setStateaccess through the proxygettrap.Suggested additional test coverage
test('return value passes isSignal (proxies the selector signal)', () => { TestBed.runInInjectionContext(() => { const store = createStore(0) const slice = _injectStore(store, (s) => s) expect(isSignal(slice)).toBe(true) }) }) + + test('supports lazy store factories when exposing actions', async () => { + `@Component`({ + template: ` + <p>{{ count() }}</p> + <button id="inc" (click)="count.inc()">Inc</button> + `, + standalone: true, + }) + class LazyStoreCmp { + initial = input.required<number>() + store = createStableSignal(() => + createStore({ count: this.initial() }, ({ setState }) => ({ + inc: () => setState((prev) => ({ count: prev.count + 1 })), + })), + ) + count = _injectStore(this.store, (state) => state.count) + } + + const initial = signal(1) + const { getByText, container } = await render(LazyStoreCmp, { + bindings: [inputBinding('initial', initial)], + }) + + expect(getByText('1')).toBeInTheDocument() + container.querySelector<HTMLButtonElement>('button#inc')?.click() + expect(await screen.findByText('2')).toBeInTheDocument() + })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/angular-store/tests/index.test.ts` around lines 500 - 506, Add a test that exercises _injectStore with a lazy store factory (instead of a direct store) to ensure the proxy get trap correctly forwards methods and signals; specifically, inside TestBed.runInInjectionContext create a lazy factory that returns createStore(0) (or similar), call _injectStore with that factory, then assert isSignal on the returned slice and also call proxyed methods like .inc() and .setState (or the store's mutation methods) through the proxy and verify the underlying store state changes — target the functions _injectStore, createStore, and TestBed.runInInjectionContext when adding this regression test.🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@packages/angular-store/tests/index.test.ts`: - Around line 500-506: Add a test that exercises _injectStore with a lazy store factory (instead of a direct store) to ensure the proxy get trap correctly forwards methods and signals; specifically, inside TestBed.runInInjectionContext create a lazy factory that returns createStore(0) (or similar), call _injectStore with that factory, then assert isSignal on the returned slice and also call proxyed methods like .inc() and .setState (or the store's mutation methods) through the proxy and verify the underlying store state changes — target the functions _injectStore, createStore, and TestBed.runInInjectionContext when adding this regression test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
d103ae0e-5534-4207-a8fc-6db4240d47fe📥 Commits
Reviewing files that changed from the base of the PR and between f7603d5d522a52fc70f9855ddd8d38a92c4de33c and 3abbb66166f012aa5c5ec1bb3a8d373cf873c145.
📒 Files selected for processing (3)
packages/angular-store/src/injectSelector.tspackages/angular-store/tests/index.test.tspackages/angular-store/tsconfig.spec.json
✅ Files skipped from review due to trivial changes (1)
- packages/angular-store/tsconfig.spec.json
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/angular-store/src/injectSelector.ts
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
Diff Package Supply Chain
SecurityVulnerability Quality Maintenance License @testing-library/angular@19.3.0 @analogjs/vitest-angular@2.5.2 Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@packages/angular-store/src/injectAtom.ts`: - Around line 50-55: The wrapper currently forwards to _atom.set(updaterOrValue as never) which discards the proper Atom<T>['set'] typing; update injectAtom so value.set (declared as WritableAtomSignal<T>) forwards the argument with the correct type instead of casting to never — for example, keep value.set signature as Atom<T>['set'] and call _atom.set(updaterOrValue as Parameters<Atom<T>['set']>[0]) or generically type injectAtom so _atom.set accepts the same parameter type; change the forwarding in value.set (the wrapper around _atom.set) to preserve Atom['set'] typing rather than using never.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
277ccddf-b10a-4275-9507-2dcb6d26fc58📥 Commits
Reviewing files that changed from the base of the PR and between f85dcb20b550c6fa57d4d07f25439ed6a051c5c4 and 4043047f91aa910fb3ded4f272b0382fe8e6d739.
📒 Files selected for processing (1)
packages/angular-store/src/injectAtom.ts
packages/angular-store/src/injectAtom.ts lines 50 to 55Resolvedby benjavicente(GitHub profile, opens in a new tab)@@ -42,10 +41,15 @@4241 * ```4342 */4443 export function injectAtom<TValue>(45- atom: Atom<TValue>,44+ atom: Atom<TValue> | (() => Atom<TValue>),4645 options?: InjectSelectorOptions<TValue>,4746 ): WritableAtomSignal<TValue> {48- const value = injectSelector(atom, undefined, options)49- const atomSignal = (() => value()) as WritableAtomSignal<TValue>50- atomSignal.set = atom.set51- return atomSignal47+ // In the future, this could be updated to use a linkedSignal setter48+ // https://github.com/angular/angular/pull/6870849+ const value = injectSelector(atom, undefined, options) as WritableAtomSignal<TValue>50+ value.set = (51+ updaterOrValue: TValue | ((prevVal: TValue) => TValue),52+ ): void => {53+ const _atom = typeof atom === "function" ? atom() : atom54+ _atom.set(updaterOrValue as never)55+ }⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -euo pipefail # Inspect Atom declarations / set signatures in the repo rg -nP --type=ts "\b(interface|type)\s+Atom\b|\bset\s*:\s*\(|\bset\s*\(" packages -C2 # Confirm current wrapper implementation details in injectAtom rg -nP --type=ts "value\.set\s*=|as never|Parameters<Atom<" packages/angular-store/src/injectAtom.ts -C2Repository: TanStack/store
Length of output: 15436
🏁 Script executed:
#!/bin/bash set -euo pipefail # Show relevant types + implementation around the wrapper in injectAtom.ts sed -n '1,140p' packages/angular-store/src/injectAtom.ts # Show Atom contract sed -n '1,120p' packages/store/src/types.tsRepository: TanStack/store
Length of output: 3485
🏁 Script executed:
#!/bin/bash set -euo pipefail # Search for the cast pattern and similar wrapper implementations rg -n --type=ts "as never" packages/angular-store/src rg -n --type=ts "Parameters<Atom<.*\['set'\]>" packages rg -n --type=ts "\.set\(.*as never" packages rg -n --type=ts "set: Atom<.*>\['set'\]" packages/angular-store/srcRepository: TanStack/store
Length of output: 141
Preserve
Atom['set']typing instead of casting tonever.WritableAtomSignal<T>already declaresset: Atom<T>['set'], butinjectAtomstill calls_atom.set(updaterOrValue as never)in the wrapper.♻️ Proposed fix
- value.set = ( - updaterOrValue: TValue | ((prevVal: TValue) => TValue), - ): void => { + value.set = (...args: Parameters<Atom<TValue>['set']>): void => { const _atom = typeof atom === "function" ? atom() : atom - _atom.set(updaterOrValue as never) + _atom.set(...args) }📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change50- value.set = (51- updaterOrValue: TValue | ((prevVal: TValue) => TValue),52- ): void => {53- const _atom = typeof atom === "function" ? atom() : atom54- _atom.set(updaterOrValue as never)55- }50+ value.set = (...args: Parameters<Atom<TValue>['set']>): void => {51+ const _atom = typeof atom === "function" ? atom() : atom52+ _atom.set(...args)53+ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/angular-store/src/injectAtom.ts` around lines 50 - 55, The wrapper currently forwards to _atom.set(updaterOrValue as never) which discards the proper Atom<T>['set'] typing; update injectAtom so value.set (declared as WritableAtomSignal<T>) forwards the argument with the correct type instead of casting to never — for example, keep value.set signature as Atom<T>['set'] and call _atom.set(updaterOrValue as Parameters<Atom<T>['set']>[0]) or generically type injectAtom so _atom.set accepts the same parameter type; change the forwarding in value.set (the wrapper around _atom.set) to preserve Atom['set'] typing rather than using never.
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 38ccc0b7b17162a488e1ce9ce033cca8e1608b30
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
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