-
Notifications
You must be signed in to change notification settings - Fork 536
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
tree: Add schema symbol to TreeNodes to allow NodeKind based narrowing. #22222
Conversation
Co-authored-by: Joshua Smithrud <[email protected]>
function getKeys(node: TreeNode & WithType<string, NodeKind.Map | NodeKind.Object>): string[]; | ||
function getKeys(node: TreeNode): string[] | number[]; | ||
function getKeys(node: TreeNode): string[] | number[] { | ||
const schema = Tree.schema(node); |
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.
Best practices question, since this example is end-user-facing: should we use a switch
here with a default handler that errors on unrecognized node kind? I don't know how likely it is that we will add a fundamentally new node type any time soon, but if we were to do so, the default behavior here may not be what the user wants.
Seems like the switch pattern highlights this potential better. Curious what others think.
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.
Done.
packages/dds/tree/src/index.ts
Outdated
type TreeObjectNodeUnsafe, | ||
type InsertableTreeNodeFromImplicitAllowedTypesUnsafe, | ||
type TreeArrayNodeUnsafe, | ||
type TreeMapNodeUnsafe, | ||
type InsertableObjectFromSchemaRecordUnsafe, | ||
type InsertableTreeFieldFromImplicitFieldUnsafe, | ||
type FieldSchemaUnsafe, | ||
// System types (not in Internal types for various reasons, like doc links or cannot be named errors). | ||
getJsonSchema, |
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.
This function isn't a @system
type. Should probably go somewhere else.
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.
Messed up some copy paste there. Fixed.
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.
Left a couple more questions, but overall looks good to me
⯅ @fluid-example/bundle-size-tests: +603 Bytes
Baseline commit: 425111e |
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output
|
Description
See changeset for details.
This will be used for things like providing object node specific events with strong typing.
This is aimed to provide the functionality attempted in alexvy86#7 to better support node kind specific data in #22043
Reviewer Guidance
The review process is outlined on this wiki page.