Skip to content

Conversation

@jason-ha
Copy link
Contributor

@jason-ha jason-ha commented Nov 22, 2025

Remove number as a possible type for LatestMap keys. All given keys are stored as string record entries at runtime and thus numbers become keys. To use "number" keys, string pattern ${number} can be used for the type.

Add keyValidator to support enabling consumers to only work with validated keys. A keyValidator is recommended anytime Keys type is not string.

A `keyValidator` may now be given when creating a `LatestMap` such that only validated keys are enumerated.
@jason-ha jason-ha requested a review from tylerbutler November 22, 2025 00:59
@github-actions github-actions bot added area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct public api change Changes to a public API base: main PRs targeted against main branch labels Nov 22, 2025
Copy link
Member

@tylerbutler tylerbutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, there's no way for a user to access or enumerate keys for which the validator returns undefined. I can understand this behavior for iteration, but it seems odd that .get(invalidKey) is the same as .get(missingKey). In practice maybe that distinction doesn't matter much.


// @beta @input
export interface LatestMapArguments<T, Keys extends string | number = string | number> extends LatestMapArgumentsRaw<T, Keys> {
keyValidator?: StateSchemaValidator<Keys>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this optional long-term? If I recall correctly, we decided to make the main validator required since we believe it's best practice to use runtime validation in addition to the compile-time. I can understand how key validation might be more optional, but do we lose any compile-time help with this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that it can stay optional. We can guarantee that keys are string | number. Key validator would only be useful if you wanted to reduce from there.
With the new proposal to return a boolean, we can actually change the signature to keyValidator(key: string | number): asserts key is Keys. When not provided, there wouldn't be anything to infer the Key type, but it should work when provided. I think the optionality won't matter. I will confirm.

@jason-ha
Copy link
Contributor Author

If I understand correctly, there's no way for a user to access or enumerate keys for which the validator returns undefined. I can understand this behavior for iteration, but it seems odd that .get(invalidKey) is the same as .get(missingKey). In practice maybe that distinction doesn't matter much.

Good question. With a keyValidator, the difference would be that the keyValidator would be invoked. So, it could be written to snoop whether something was invalid or missing.
I think we'll need to see if there is desire for something nicer.

…testMap`

`number`s have always propagated as `string`s at runtime. Removal of specification makes API types reflect this.

Internally, `objectEntries` appears to fail to fully preserve key enumeration not that `number` is not possible.
@github-actions
Copy link
Contributor

🔗 No broken links found! ✅

Your attention to detail is admirable.

linkcheck output


> fluid-framework-docs-site@0.0.0 ci:check-links /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test "npm run serve -- --no-open" 3000 check-links

1: starting server using command "npm run serve -- --no-open"
and when url "[ 'http://127.0.0.1:3000' ]" is responding with HTTP status code 200
running tests using command "npm run check-links"


> fluid-framework-docs-site@0.0.0 serve
> docusaurus serve --no-open

[SUCCESS] Serving "build" directory at: http://localhost:3000/

> fluid-framework-docs-site@0.0.0 check-links
> linkcheck http://localhost:3000 --skip-file skipped-urls.txt

Crawling...

Stats:
  249533 links
    1776 destination URLs
    2013 URLs ignored
       0 warnings
       0 errors


@jason-ha jason-ha changed the title feat(client-presence): LatestMap key validation option fix(client-presence): [BREAKING CHANGE] LatestMap keys limited to strings Nov 25, 2025
@jason-ha jason-ha requested a review from tylerbutler November 25, 2025 21:06
@jason-ha jason-ha linked an issue Nov 25, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch changeset-present public api change Changes to a public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

presence: Removal of number key support in LatestMap in v2.80

2 participants