-
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
Disable additional .array() modifier #406
Conversation
🦋 Changeset detectedLatest commit: 155fa09 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
In addition to addressing the comment on the internal symbol, let's also please add some testing. (Ideally in defined-behavior
.)
Thanks!
/** | ||
* Internal non-omittable method to pass the test, won't be used by customers. | ||
*/ | ||
[internal](): ModelField<T, UsedMethod>; | ||
//TODO: should not be needed. Fix 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 in BaseModelField
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 in ModelField.test-d.ts
suggest TypeScript cannot infer the correct type any more unless there is a method in place for ModelField
.
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 from ModelField
. 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 reference ModelField
's T
type arg.
If we just omit array
without adding another property:
This causes BaseModelField
to lose the type information in T
that was assigned or modified by the modifier methods on ModelField
and the type argument defaults to ModelFieldTypeParamOuter
. So any consumers of BaseModelField
cannot infer any specific type metadata out of it, e.g. the underlying field type, nullability, "arrayness".
Adding another property that references T
, keeps BaseModelField
intact.
OK. So, the fact that this is a method and not just a regular property is kind of incidental?
Bingo. We just need some non-omittable property that maintains a reference to T
. Simplest form would be:
{
[internal]: T;
}
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.
{
[internal]: ModelType<T>;
}
And then something like
{
...,
[internal]: _field(ModelFieldType.String)
}
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.
I have added a unit test in
|
abb0569
into
aws-amplify:feat/reinvent-blocked-days/main
Co-authored-by: Ivan Artemiev <[email protected]>
Related issues:
Description of changes:
This change disables customers from chaining
.array()
modifier in model field definition. It adds.array()
method to the used method list after being called.Example of why we need this:
Currently customers can declare a double array for a data field, which will cause errors and is not what we intended.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.