Skip to content
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

example for TypeSerializer<TSerialized, TOriginal> optional properties? #13

Open
janseng1970 opened this issue Dec 10, 2019 · 3 comments
Assignees
Labels

Comments

@janseng1970
Copy link

Hello,

is there any example for using @Serialize.Custom with this optinal properties in the TypeSerializer<TSerialized, TOriginal> interface?

/**
 * _Optional._ Original type constructor function.
 * Default: Value of `design:type` for given property.
 */
type?: Constructable.Default<TOriginal>;
/**
 * _Optional._ Property type descriminator function.
 * Used to narrow type constructor function (e.g. for union types)
 * @param serialized Serialized value
 * @returns Original type constructor function
 */
discriminate?(this: void, serialized: TSerialized): Constructable.Default<TOriginal>;

I google the code go in deep for the inflate and deflate function and can not even find, that this two properties are used. I want to use the discriminate function to map the name of a type, stored in a serialized string property to a type via a "typemapper".

Thanks for help!

Georg

@teq
Copy link
Owner

teq commented Dec 10, 2019

Hey Georg,

This discriminate functionality was never fully implemented. Later I decided that it adds unnecessary complexity to the library and the same effect can be achieved by providing custom up/down functions. So, I removed it completely in v3 (develop branch, can be installed with npm i serialazy@next). Also, you can check a CHANGELOG for more info on changes.

@teq teq self-assigned this Dec 10, 2019
@teq teq added the question label Dec 10, 2019
@teq
Copy link
Owner

teq commented Dec 10, 2019

Btw, can you provide a complete example of what you're trying to do?

@janseng1970
Copy link
Author

Hello,
thanks for the interesst! May be you find some inspiration or you just shake your head.

I want to compine polymorphism with generics and want to define the serialisation in the generic. To do this I defined an interface "NamedType", an interface that yust defined the the property "public typeName: string" witch will be serialised (and will be transported over axios or some like that). So I will serialize some thing like an Array (or List-, Tree- or Collection- Generic) of for example a "Person" - Class with can in detail be instance of "Teacher" or "Student" witch extends "Person". So up/inflate the generic Array has to translate the array elements with typeName="Teacher" to a instance of Teacher - Class and typeName="Student" to an Student - Class. I try to define this mapping in the Array generic (or Tree generic) and only want to define the mapper like (typeName: string) => T later on the level I want to use the generic.

I hope I make it clear, I dont expect a solution. I am still working on my challange.

Thanks,

Georg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants