Skip to content

Deserialize to class expecting generic type #154

@kpenergy

Description

@kpenergy

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions