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
tree2: Cleanup creation of field schema #17699
tree2: Cleanup creation of field schema #17699
Conversation
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.
Looks good. I have one question. You changed many of places where AllowedTypes are passed in to be arrays rather than single elements. Is that a convention that you are favoring? Or is it now mandatory? I don't see where it would have changed to be mandatory, but I wanted to ask.
experimental/dds/tree2/src/feature-libraries/typed-schema/typedTreeSchema.ts
Outdated
Show resolved
Hide resolved
experimental/dds/tree2/src/feature-libraries/typed-schema/typedTreeSchema.ts
Outdated
Show resolved
Hide resolved
experimental/dds/tree2/src/feature-libraries/typed-schema/typedTreeSchema.ts
Outdated
Show resolved
Hide resolved
⯅ @fluid-example/bundle-size-tests: +890 Bytes
Baseline commit: 96d9e2a |
Co-authored-by: Noah Encke <78610362+noencke@users.noreply.github.com>
FieldSchema works in terms of AllowedTypes, which is always an array. The places that were converted to call its create functions which didn't explicitly use arrays were using variadic functions, which was a workaround for us not having a version of typescript with https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters . This patterns is bad, mainly because it makes the almost never intended case of passing an empty array look like the default behavior. Note that none of these are the preferred customer facing API which is in our internal spec, which all are on SchemaaBuilder and take ImpliedAllowedTypes, which accepts both array and single argument forms, but will not (and cannot) tolerate recursive types. Thus I expect the only real use in app code these APIs will be FieldSchema.createUnsafe as part of recursive types. |
Description
Adopts a new pattern for documenting workarounds for microsoft/TypeScript#55758, making the documentation more centralized, and more clear about what the desired extends clauses are.
Also avoids using the constructor for FieldSchema and instead use static builders whose type parameters can be constrained.
This, when combined with
const
generic type parameters removes the reason for existence of the generic FieldSchema builders on SchemaBuilder, so those have been removed (the ones which depend on specific field kinds are kept).Also adds some runtime validation in FieldSchema for cases the type system can't fully handle.
Breaking Changes
Users of SchemaBuilder.field (or new FieldSchema) and SchmeaBuilder.fieldRecursive should use FieldSchema.create and FieldSchema.createUnsafe.
Reviewer Guidance
The review process is outlined on this wiki page.