-
Notifications
You must be signed in to change notification settings - Fork 559
fix(client-presence): [BREAKING CHANGE] LatestMap keys limited to strings
#25904
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
base: main
Are you sure you want to change the base?
Conversation
A `keyValidator` may now be given when creating a `LatestMap` such that only validated keys are enumerated.
tylerbutler
left a comment
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.
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>; |
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.
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?
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.
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.
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. |
…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.
add key validator test coverage
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
LatestMap keys limited to strings
Remove
numberas a possible type forLatestMapkeys. 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
keyValidatorto support enabling consumers to only work with validated keys. AkeyValidatoris recommended anytimeKeystype is notstring.