ngrx/platform

Types of property '[STATE_SOURCE]' are incompatible error when testing using `patchState` after v18 upgrade

Closed this issue · 1 comments

Which @ngrx/* package(s) are the source of the bug?

signals

Minimal reproduction of the bug/regression with instructions

Simple Signal Store with a basic test. Can no longer call patchState inside test due to incompatible types.

image

https://stackblitz.com/~/github.com/dancoto/signal-store-testing-issue?file=src/store.spec.ts

Expected behavior

This was working in v17. Currently breaking all tests that use patchState in v18

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

"dependencies": {
"@angular/animations": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler": "^18.0.0",
"@angular/core": "^18.0.0",
"@angular/forms": "^18.0.0",
"@angular/platform-browser": "^18.0.0",
"@angular/router": "^18.0.0",
"@ngrx/signals": "^18.0.2",
"jest": "^29.7.0",
"rxjs": "^7.8.1",
"tslib": "^2.5.0",
"zone.js": "~0.14.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.0",
"@angular/cli": "^18.0.1",
"@angular/compiler-cli": "^18.0.0",
"@types/jest": "^29.5.12",
"typescript": "~5.4.0"
}

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No

This is intended behavior - from v18, SignalStore's state cannot be directly updated from outside by default.

Although it's not recommended in most cases, it's possible to allow direct state updates outside the store by adding protectedState: false when defining a SignalStore. Check NgRx Signals v18 article (section "State Encapsulation") or official documentation for more info.