-
Notifications
You must be signed in to change notification settings - Fork 362
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
Add ObserverMixin to ModelBase typings #1823
Conversation
af653c8
to
fff92b8
Compare
This is actually a breaking change. Before, a value of type With my change in place, this is no longer possible, because |
fff92b8
to
1a8af55
Compare
As I was thinking about this problem, I came to the conclusion that we should prefer ease of use and ergonomics of our typings over implementation simplicity. The original implementation in fff92b8 was based on changing I have reworked this pull request to simply copy typings of the public members of I have verified that The code here is prepared to support better-typed Operation Hook Context introduced in #1820 🚀 I consider this PR as ready for review. @emonddr @zbarbuto @jannyHou @dhmlau PTAL. /cc @hacksparrow @raymondfeng - I'd like to hear your opinions too. |
1a8af55
to
840e4e4
Compare
@bajtos there is at least one place where |
As I understand the API, I think you need to fix those places and modify |
AFAICT, your PR loopbackio/loopback-next#4730 uses the following two variants, both of them are correct:
Notice that in the second case, we are using |
Data.observe('before save', async ctx => {}); | ||
|
||
// ModelBaseClass can be assigned to `typeof ModelBase` | ||
const modelTypeof: typeof ModelBase = Data; |
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.
Please add a comment that ModelBaseClass
is an alias of typeof ModelBase
and we are testing the alias here. thx.
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.
See 6c38347, is my comment good enough?
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.
The comment is great. thx. But a tiny typo: verifying that the value retunred
840e4e4
to
6c38347
Compare
I linked my modified version of juggler into |
a0f95a5
to
c38b96c
Compare
Created #1825 to fast-track landing of |
c38b96c
to
5ef915c
Compare
Signed-off-by: Miroslav Bajtoš <[email protected]>
5ef915c
to
c7b88e9
Compare
Cross-posting from Slack.
Please start here:
Here is what we want to describe: for a model extending from If Regarding
For example, a mocha test function returning a promise is typed as Now in our case, by using
Because observer API is mixed into the class constructor ( |
Signed-off-by: Miroslav Bajtoš <[email protected]>
Added b01cd74 to capture some of the information from my comment above. |
See #1820 and loopbackio/loopback-next#4730.
Model APIs
ModelBaseClass
PersistedModelClass
typeof KeyValueModel
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machine