-
Notifications
You must be signed in to change notification settings - Fork 124
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
Custom Types, Custom Serialization, Custom Validation #617
Comments
I tried to implement the use-case you had with almost exactly that code from you and although it is possible to support it, it was not simple and also I found an interesting bug with symbol in methods names (the same you got "Symbol.iterator(type): Not a function"). So I fixed them and added a custom iterable examples in our unit tests: https://github.com/deepkit/deepkit-framework/blob/master/packages/type/tests/use-cases.spec.ts You have to update to newest version To answer your questions:
|
Alright, thanks for the patch and the examples, that resolved the issue with decoding types that had iterator conformance. On No.3, this is definitely your This project I’m working on is built on React and I’m using both the React SWC and the Deepkit plugins, as per that one sample project. I managed to untangle from the issues I’ve described here only to run into other cases where either types just weren’t available or What actually are the limitations? Do I have to explicitly specialise every generic function call? Do I have to manually append I’m starting to suspect it has something to do with how types are imported and exported around — but then again, many things seem to work in a clean demo. |
What do you mean you are using React SWC and Deepkit plugins? My last knowledge of SWC was that they do not support JS plugins, so it's impossible to hook Deepkit into SWC. I can only assume you use Vite to use merge both SWC and Deepkit plugin. If you disabled minification/optimisations in Vite, you can look at the dist JS source code and see if type information were correctly embedded.
That's too vague for me. Please show minimalistic fully-working source code that does not work for you. This is the most efficient way to get accurate answers.
Even in an actual project it's always possible to isolate code into a small file that contains everything needed. Once this file goes through you full build pipeline, you see the JS and can execute it. This way you see quickly what is going on. The less code you have that triggers the wrong behaviour, the better.
You can provide minimalistic working code here as well to get fast solutions. Feel free to join Discord, this way you get even faster help without the need to fight on your own. |
So I’m very close to my breaking point with this entire project, I’ve spent over a week now getting everything working, from the compiler integration, source mapping, debugging, and now actually deserializing types. I’ve been stuck at generic data models that worked 1:1 in a demo but didn’t in my big project. I think the docs are lacking when it comes to custom types.
This issue is for a use case I think is actually really trivial, effectively a subclass of
Set<T>
. The stripped code is:The steps I had a lot of issues with:
OrderedSet<T> extends Set<T>
but DeepKit didn’t serialize it like it did withSet<T>
, the assumed encoded form was object-like not array-like, like it handledSet
but that is what I needed.annotateClass<Set>(OrderedSet)
but that didn’t deserialize to anOrderedSet
, it’s been a while but I think that just decoded to anArray<T>
, effectively didn’t transform anything.static {}
block for it.addSetter
does not have a scope except for a global one. As far as I can see, there is no way to passOrderedSet
to it. Serializing here would be trivial, just output as an array — but I obviously need the actual type for deserialization.deserialize<T>(…)
now works as expected with any type usingOrderedSet
internally.cast<T>(…)
still throws an error. Apparently, it fails at the iterator property in the type and this is where I’m just completely lost. Where am I?serializer.validators
?serializer.typeGuards
? Somewhere outsideserializer
?So all in all, I have two plus one questions:
Set<T>
and deserialize vianew OrderedSet<T>(…)
?ValidationError2
?The text was updated successfully, but these errors were encountered: