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

Deserialize to class expecting generic type #154

Open
kpenergy opened this issue Jul 27, 2021 · 0 comments
Open

Deserialize to class expecting generic type #154

kpenergy opened this issue Jul 27, 2021 · 0 comments

Comments

@kpenergy
Copy link

It it possible to use this library to deserialize JSON to an instance of a class that expects a generic type argument?

For example:

class MyMessage<T> {
    Id!: string;
    Payload!: T;
}

class MyPayload {
    Data!: string;
}

const instance = new MyMessage<MyPayload>();
instance.Id = "TEST1";
instance.Payload = new MyPayload();
instance.Payload.Data = "PAYLOAD DATA";

const serialized = serialize(instance);
const deserialized = deserialize(MyMessage<MyPayload>, serialized);

This gives the following compile error:

Operator '<' cannot be applied to types 'typeof MyMessage' and 'typeof MyPayload'.

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

No branches or pull requests

1 participant