-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(signals): set state in patchState
to readonly
#4519
base: main
Are you sure you want to change the base?
feat(signals): set state in patchState
to readonly
#4519
Conversation
✅ Deploy Preview for ngrx-io canceled.Built without sensitive environment variables
|
@@ -27,3 +27,11 @@ export type IsKnownRecord<T> = IsRecord<T> extends true | |||
export type OmitPrivate<T> = { | |||
[K in keyof T as K extends `_${string}` ? never : K]: T[K]; | |||
}; | |||
|
|||
export type DeepReadonly<T> = T extends object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type-fest
library has a more comprehensive version of this: https://github.com/sindresorhus/type-fest/blob/main/source/readonly-deep.d.ts. I can't tell the differences off the top of my head but thought I'd mention it.
(Note: I'm not advocating using the type-fest
library as a dependency — more providing this in case of inspiration for some good 'ol copy-pasting :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jits, I took a look at it before. It supports a lot of types that are not allowed to be part of the state object. So I took arrays, primitive types and nested objects out of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rainerhahnekamp — ahh, perfect! Thanks for clarifying. (And that makes a lot of sense)
I suggest keeping types as they are and displaying a warning in dev mode if the state is mutated. |
As discussed in #4030, the update function of
patchState
, provides the state as deep readonly.Notes on the test: I've decided to go with
@ts-expect-error
instead of ts-snippet. ts-snippet requires the source code as string, whereas @ts-expect-error can be applied to normal code. This makes it easier to write but also to refactor.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #4030
What is the new behavior?
Does this PR introduce a breaking change?