Skip to content

Using class-transformer with polytype #13

Answered by fasttime
aru-py asked this question in Q&A
Discussion options

You must be logged in to vote

I believe that class-transformer is assuming that every constructor has a prototype. I don't know why they are doing that, but I can think of other cases where that code would fail. You may want to report this issue to class-transformer.

import { plainToInstance } from "class-transformer";

function Base() { }
Object.setPrototypeOf(Base, null);
class Derived extends Base { }

// throws error
const obj = plainToInstance(Derived, { });

Note that in this example, Derived is a valid, instantiable and subclassable class.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aru-py
Comment options

Answer selected by aru-py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants