alexeyraspopov / dataclass

Data classes for TypeScript & JavaScript

Home Page:https://dataclass.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

copy() method makes plain Object (TypeScript)

opened this issue · comments

Hi. Thanks for the great lib, just what I was looking for.
I have found that copy() produces just a plain JS object and I lose all extra methods and features.
But it works as expected if I change the copy() method in the dataclass this way::
- return new this.constructor(custom);
+ return new (Object.getPrototypeOf(this)).constructor(custom);
Not sure though if it is applicable for all cases.
Gist for tests

@art-mickiewicz, thank you for reporting the issue! I've published v1.0.2 with the fix you've suggested. It worked for me locally, however, I'll try to additionally investigate the root cause — it never happened to me before.

Please let me know if updated version works for your case. Thanks.