-
Notifications
You must be signed in to change notification settings - Fork 148
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 type-safety to Record class #532
Conversation
Hi @parzhitsky can you please resolve the merge conflicts, thanks for contributing. Cheers Martin |
c8e7409
to
437b430
Compare
Is there anything else I can do with this PR? |
@parzhitsky Sorry for the delay, we do not have any one at the moment to review your Typescript improvements. |
Oh, got it. Please take your time, no worries |
Is there any chance of this getting merged soon? It would be a really nice feature to have. |
Sorry for the delay, @parzhitsky. Could you please move the target branch to 4.3? |
437b430
to
acbcc01
Compare
This commit adds ability to create type-safe Record entities by assigning type to Record's value. The implementation is based on adding type parameters to types, interfaces, and classes. It is implemented however in a backwards-compatible manner, so that opting in to type safety is optional. Examples: // before (unsafe) const record = new Record(['name'], ['Alice']) record.get('neam') // no errors record.toObject().neam[0] // run-time (late) error // after (safe) const record = new Record<Person>(['name'], ['Alice']) record.get('neam') // Error: does not exist record.toObject().neam[0] // design-time (early) error
acbcc01
to
9202515
Compare
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.
@parzhitsky Thanks for your contribution, should i merge it?
I will back port to 4.2 after merged, but I will wait a bit for the release it.
@bigmontz Sorry, I didn’t get the point. Could you rephrase it? No offense 🙂 Should be okay to merge the PR. |
I will release this feature in the 4.2.x in the near future (one week, or something like this), I will wait a bit to see if I manage to join it with other improvements or fixes. |
Hi @parzhitsky, I've released this improvement on the version 4.2.2 of the driver. Thanks for your contribution. |
Happy to help! 🙂 |
Description
This PR adds ability to create type-safe Record entities by assigning type to Record's value.
The implementation is based on adding type parameters to types, interfaces, and classes. It is implemented however in a backwards-compatible manner, so that opting in to type safety is optional.
Usage
Before (unsafe):
After (safe):