-
Notifications
You must be signed in to change notification settings - Fork 547
feat(client-core-interfaces): DeepReadonly
and ShallowReadonly
utility types
#24265
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
Conversation
…ility types Alternates to `Readonly` that handle `Map`s, `Set`s, `Promise`s, `WeakMap`, and `WeakSet` by providing readonly equivalents. The generic types of those and `IFluidHandle` may also optionally be changed to readonly types. `DeepReadonly` will also apply readonly throughout the entire type not just at the outer level. Also add `ReadonlyJsonTypeWith` and (internal) `ReadonlyNonNullJsonObjectWith` as immutable versions of `JsonTypeWith` and `NonNullJsonObjectWith` respectively. These are used to create readonly versions of the `JsonTypeWith` and `NonNullJsonObjectWith` types.
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.
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/common/core-interfaces/src/jsonType.ts:52
- [nitpick] The documentation comment appears incomplete or unclear; consider revising it to clearly explain the mutability behavior of a 'const' variable.
* does not prevent later `x = 5`. (Does prevent )
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.
Approving without having carefully reviewed the type gymnastics. If it works, it works, and this change can only help avoid runtime abuse (even if it turns out to have a bug or a gap). I see there's lots of tests, so it's clear that this will provide plenty of a speed bump for anyone trying to mess with signals payloads.
Alternates to
Readonly
that handleMap
,Set
,Promise
,WeakMap
, andWeakSet
by providing readonly equivalents. The generic types of those andIFluidHandle
may also optionally be changed to readonly types.DeepReadonly
will also apply readonly throughout the entire type not just at the outer level.Additionally, the utility types respect FF's
ErasedType
and class branded primitives.Also add
ReadonlyJsonTypeWith
and (internal)ReadonlyNonNullJsonObjectWith
as immutable versions ofJsonTypeWith
andNonNullJsonObjectWith
respectively. These are used to create readonly versions of theJsonTypeWith
andNonNullJsonObjectWith
types.