mobxjs / serializr

Serialize and deserialize complex object graphs to and from JSON and Javascript classes
MIT License
766 stars 52 forks source link

Creating ModelSchema for abstract classes in TypeScript #96

Closed Hamcker closed 5 years ago

Hamcker commented 5 years ago

Attempting to create ModelSchema via createModelSchema for abstract classes causes

Argument of type 'typeof Foo' is not assignable to parameter of type 'Clazz'. Cannot assign an abstract constructor type to a non-abstract constructor type.

the complete code is something like this:

abstract class Foo { bar: string = 'bar' } const FooSchema = createModelSchema(Foo, {bar: primitive()});

1R053 commented 5 years ago

I guess this won't fix, as the class specified in a schema always needs to be instantiable in order to be deserializable.

Hamcker commented 5 years ago

Not always, but thanks to this library, I made a full-feautered serializer library for this.

1R053 commented 5 years ago

great, feel free to submit a PR here if it helps