Comments (3)
the same
from class-transformer.
The Transform decorator signature calls for a function
with return type any, which is a bit misleading (as it will work with a promise in your case at least in ts). I do not see anything that is should support for async calls. it will not await for it I. (if it would support async I think the plainToInstance, instanceToInstance and instanceToPlain functions should support async as well.The plainToInstance function should be called with the concrete data and awaited before it.
I think you would need something like
const resolvedValue = await something.organization;
const organisation = resolvedValue && 'name' in resolvedValue ? resolvedValue.name : null;
const user = plainToInstance(User, {..., organization});
I hope this helps
from class-transformer.
Closing as answered.
Note that there is an ongoing issue on async support. #549
from class-transformer.
Related Issues (20)
- question: How to expose attr when plain object no define HOT 1
- question: How to ignore Transform decorator when using plainToInstance HOT 2
- question: Getting `ReferenceError: Cannot access 'XXX' before initialization` in class circular dependency with Jest & Typescript HOT 3
- question: Constructors validation seems to break when using plainToInstance HOT 3
- Include @IsOptional values to the body if they are missing with default value HOT 2
- fix: Can't use instanceToPlain with Nitro.js event. HOT 4
- External Values are not stripped. HOT 4
- fix: plainToClass cannot handle URL values HOT 6
- feature: function support of options.discriminator.subTypes HOT 2
- plainToClassFromExist is Deprecated what is the replacement for generics? HOT 2
- Cannot transform string to number HOT 7
- question: Is class-transformer really thought to be used in the backend? HOT 4
- question: Options in @Transform Decorator Do Not Reflect Those Passed to plainToInstance in class-transformer HOT 2
- question: Casting Json to the required datatype HOT 2
- instanceToPlain not working properly using nestjs HOT 4
- fix: Expose not working correctly with toClassOnly HOT 2
- fix: bug in casting boolean properties from `@Query()` in Nest.js HOT 4
- fix: Unable to use "name" as a property in class-validator HOT 1
- fix: No Capability to BigInt? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from class-transformer.