Skip to content

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

Merged
merged 4 commits into from
Apr 22, 2025

Conversation

jason-ha
Copy link
Contributor

@jason-ha jason-ha commented Apr 7, 2025

Alternates to Readonly that handle Map, Set, Promise, 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.

Additionally, the utility types respect FF's ErasedType and class branded primitives.

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.

…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.
@Copilot Copilot AI review requested due to automatic review settings April 7, 2025 08:05
@github-actions github-actions bot added the base: main PRs targeted against main branch label Apr 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 )

@jason-ha jason-ha requested a review from tylerbutler April 7, 2025 17:08
@pragya91 pragya91 requested a review from CraigMacomber April 15, 2025 19:01
@jason-ha jason-ha requested a review from pragya91 April 18, 2025 05:04
Copy link
Member

@markfields markfields left a 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.

@jason-ha jason-ha merged commit 415ec2d into microsoft:main Apr 22, 2025
35 checks passed
@jason-ha jason-ha deleted the infra/readonly-generators branch May 25, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants