-
Notifications
You must be signed in to change notification settings - Fork 0
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
Disable additional .array() modifier #406
Merged
zxl629
merged 6 commits into
aws-amplify:feat/reinvent-blocked-days/main
from
zxl629:lzhouq/fix/disallow-array-modifier
Dec 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b57589a
Disable additional .array() modifier
zxl629 6cd8bd8
Fix spacing
zxl629 f70ead7
Add unit test
zxl629 8c90469
Add defined-behavior test
zxl629 5f86338
Clean up docstring
zxl629 155fa09
Merge branch 'feat/reinvent-blocked-days/main' into lzhouq/fix/disall…
iartemiev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/data-schema': minor | ||
--- | ||
|
||
Disable additional .array() modifier on model field definition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't understand. 😅
What am I missing?
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.
It seems that making every builder method omittable will break
BaseModelField
, as there is no method signature inBaseModelField
type. Adding an internal method here solves the issue. However, this is not a clean solution and I am not sure how to work around it.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 think this is the same problem being solved elsewhere with branding. Would a brand work to distinguish this?
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.
OK. So, the fact that this is a method and not just a regular property is kind of incidental?
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.
There is a brand property in
ModelField
. I could be wrong here but the errors showed up inModelField.test-d.ts
suggest TypeScript cannot infer the correct type any more unless there is a method in place forModelField
.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.
@stocaaro - not the same problem. By making all methods omittable, we're breaking
BaseModelField
's ability to retain generic type information fromModelField
. I'll try to illustrate below.before this change:
Note: that there's nothing special about the
array
method, we just need at least one property on this type to referenceModelField
'sT
type arg.If we just omit
array
without adding another property:This causes
BaseModelField
to lose the type information inT
that was assigned or modified by the modifier methods onModelField
and the type argument defaults toModelFieldTypeParamOuter
. So any consumers ofBaseModelField
cannot infer any specific type metadata out of it, e.g. the underlying field type, nullability, "arrayness".Adding another property that references
T
, keepsBaseModelField
intact.@svidgen
Bingo. We just need some non-omittable property that maintains a reference to
T
. Simplest form would be:But that makes the implementation side a lot clunkier. I was only able to satisfy that type with a double assertion.
We can do e.g.
And then something like
In the implementation, but that still looks worse/more arbitrary than what we've got now with the method.
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.
Ack. I think this makes sense.