-
Notifications
You must be signed in to change notification settings - Fork 131
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
Generic Delta<T>
?
#87
Comments
Hey @alecgibson 👋, Thanks for raising this up! I think in practice, you would get delta data from your database and you still have to perform a force casting ( |
My point was more that you can simplify your casting by moving the cast to the |
While this is indeed convenient, the actual data you get may not necessarily conform to your type definition (e.g. due to bugs or data format upgrades), and supporting generics can easily lead developers to overlook this issue. In practice, I'd recommended using |
I'll admit embeds do complicate things, and yes I'd agree we'd want generics for that, too if we did attributes. If there's no appetite for this, that's fair enough. Thought I'd just float the idea because I know I get bored of constantly casting, but maybe I'm just lazier than most 😛 |
For me I tend to use type guards for attributes and type force casts for embed values as attributes are generally simple values. Probably you may want to define a custom utility function |
The
AttributeMap
interface currently looks like this:While this is technically correct, it can be a bit of a pain to work with when accessing attributes programmatically, since you're constantly forced to cast (which can also be error-prone, since we're actually operating outside of type safety):
The easiest (but not type-safe) thing is obviously to change to:
But use of
unknown
was an active choice made in #73 (which is fair enough).Instead, it would be nice to let consumers define their own interfaces, for both improved type-safety and convenience:
This would require us to be able to pass a type argument to
Delta
:I started trying to put together a PR, but realised it's unfortunately not quite as simple as I'd anticipated, since
Delta
objects interact with otherDelta
objects (which is their whole point), and they may or may not share the sameOp
type.I guess in theory you could still have things like:
But before I launched into this, I thought I'd gather opinions first. Thoughts?
The text was updated successfully, but these errors were encountered: