Enhance type safety in @ngrx/signals
#4712
Replies: 1 comment 6 replies
-
@Chiorufarewerin, version 19.0.0 originally introduced built-in immutable protection, but we had to remove it because there are valid cases where developers require mutable changes. While these cases are rare, they do exist, so we ultimately had to revert the change. More details can be found here: #4683. We also considered enforcing immutability using read-only types, but after consulting with the Angular team, we decided against it. TypeScript doesn’t always guarantee full type safety, which introduces certain challenges. For those who still want immutable state enforcement, there is an opt-in community extension: withImmutableState in the ngrx-toolkit. |
Beta Was this translation helpful? Give feedback.
-
I hadn't used
@ngrx/signals
before, so recently I decided to migrate some of my services to this store. It seems really promising, especially because of its declarative approach and extensibility.However, I encountered an issue with type safety. I want to ensure that no store members can be directly modified, but currently, this is not the case.
Here is an example of a store:
And here is an example of how the store can be modified:
Suggestion
To improve type safety, I suggest making the signal store more restrictive by adding readonly to every type that should not allow direct modification.
Beta Was this translation helpful? Give feedback.
All reactions