-
Notifications
You must be signed in to change notification settings - Fork 537
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: handle schema contravariantly when generating input types #22874
Conversation
## Description Misc improvements found when working on #22874 . Many of these are places where schema types were not captured properly, or incorrect typing wasn't detected due to the incorrect variance. ## Breaking Changes The change to `InsertableObjectFromSchemaRecord` could impact something: it's strictly a bug fix but its unclear what implications its wrong version could have. I suspect no realistic code would be broken by these more correct types, but it's possible something could be impacted.
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.
Code Coverage Summary
↓ packages.dds.tree.src.simple-tree.api:
Line Coverage Change: -0.44% Branch Coverage Change: No change
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 86.53% | 86.53% | → No change |
Line Coverage | 82.12% | 81.68% | ↓ -0.44% |
↑ packages.dds.tree.src.simple-tree.core:
Line Coverage Change: 0.01% Branch Coverage Change: No change
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 93.39% | 93.39% | → No change |
Line Coverage | 97.22% | 97.23% | ↑ 0.01% |
↑ packages.dds.tree.src.simple-tree:
Line Coverage Change: 0.09% Branch Coverage Change: 0.01%
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 93.29% | 93.30% | ↑ 0.01% |
Line Coverage | 97.13% | 97.22% | ↑ 0.09% |
↑ packages.dds.tree.src.events:
Line Coverage Change: 2.09% Branch Coverage Change: No change
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 92.00% | 92.00% | → No change |
Line Coverage | 68.46% | 70.55% | ↑ 2.09% |
↑ packages.dds.tree.src.util:
Line Coverage Change: 6.23% Branch Coverage Change: 0.40%
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 96.34% | 96.74% | ↑ 0.40% |
Line Coverage | 73.80% | 80.03% | ↑ 6.23% |
Baseline commit: a1b4cdd
Baseline build: 303010
Happy Coding!!
Code coverage comparison check passed!!
⯅ @fluid-example/bundle-size-tests: +245 Bytes
Baseline commit: a1b4cdd |
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.
Just some nits. Approved for docs.
Co-authored-by: Tyler Butler <[email protected]>
const view = sharedTree.viewWith(config); | ||
|
||
// Does not compile since setter for root is typed `never` due to imprecise schema. | ||
view.root = []; |
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.
Curious: what does the error look like in this case? Is it intelligible?
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.
its cannot assign [] to never
I believe. I know what that means, but not sure if others would.
* @see {@link Input} | ||
* | ||
* @typeparam TSchema - Schema to process. | ||
* @typeparam TResult - Do not specify: default value used as implementation detail. |
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 take it there is no reasonable way for us to hide these parameters that we strictly want to be inferred? I can't think of one, but you know TypeScript's generics way better than I do.
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.
Adding extra dummy parameters is just a way to have variables in these type computations which can be reused. I think its cleaner than making an additional "inner" type which we also would have to export. We could also just copy past the expression into every use site.
I don't find either of those workarounds better, but they are options we could take instead.
In this specific case though these docs are stale and there is no such parameter: oops!
@@ -229,13 +229,15 @@ | |||
"typeValidation": { | |||
"broken": { | |||
"TypeAlias_InsertableTreeFieldFromImplicitField": { |
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.
Sanity check: these are all @system
or @internal
exports?
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.
Type tests are basically meaningless for generic types since they just pass in any
, and we don't actually define what using a schema of any
is supposed to result in. There are real and important breaking changes that these do not catch (like those called out in the changeset: type tests didn't detect those), and non breaking changes (like adding a defaulted parameter you aren't allowed to use) which it considers breaking (as is the case for this one).
And no, these are not all system. This one is just public for example.
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.
Also, @internal
types won't be included here since they are filtered based on release tag. We have some public type exported in the InternalTypes module, but those are not actually @internal
just a flawed attempted to try and make systems types not get mixed in with the others.
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 handful of suggestions and questions. Biggest question: how confident are we that the type-wise breaking changes made here will not disrupt the majority of users?
Co-authored-by: Joshua Smithrud <[email protected]>
It's hard to tell. It did break our in repo ai-collab code, but it's doing non-schema aware editing. I don't really know how many people are doing things that we never intended to support and are unsafe. I'll do a test build and try it in the examples repo. |
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.
Didn't go through the functional changes, just looked at the changesets and left a couple of suggestions, but they otherwise look good. Definitely worth getting more approvals, particularly from API council given the breaking change.
I have done the test integration into the examples repo. It has some preexisting problems, but I don't see anything new from these changes. |
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output
|
Description
Handle schema contravariantly when generating input types.
Breaking Changes
No runtime changes, but typing tweaks could break users on non-exact schema, and the enum schema APIs have been tweaked to avoid relying on non-exact schema, see changeset.
Reviewer Guidance
The review process is outlined on this wiki page.