-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
class-transformer-shim: support metadata reflection #4219
Comments
Huge thanks for bringing this up, I am currently "reviving" all dates individually and manually on the front end and forgetting this is often a source of bugs for us. I am not familiar with the use of reflect-metadata, have you managed to implement a bridge from typeORM's date annotation to class-transformer ? |
@Michael-Dawkins yes, it's already included in the latest release :) You have to include typeorm-class-transformer-shim.js into your tsconfig.json "paths": {
"typeorm": [ "node_modules/typeorm/extra/typeorm-class-transformer-shim.js" ]
} |
You just made my day. I've been thinking for months it would be nice to simply use the annotations already present from using TypeORM or heck, even typescript. By reading class-transformer's doc again today, I also discovered "enableImplicitConversion"'s new option of class-transformer which is a nice addition. |
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)TypeORM provides a class-transformer-shim, which is awesome for browser/fronend application usage.
However, the transformation of
Date
types for example - or any other type, that isn't passed via a decorator and a typeFunction - requires additionalclass-transformer
code:To make it work, we need to write:
which I find annoying, especially when sharing entities between backend and frontend. One would also have to import the
class-transformer
library into his backend, but actually it's only used on the frontend side. Plus of course, it saves us lots of code lines.We could solve this, if typeorm-class-transformer-shim.js would support metadata reflection.
If the client imports "reflect-metadata", we could use
design:type
and automatically pass it to the@Type
decorator of class-transformer, as we already do with typeFunctions.PR is on the way.
The text was updated successfully, but these errors were encountered: