Skip to content

Commit 4801072

Browse files
committed
docs: rephrase docs from pr comments
1 parent d0d5f1e commit 4801072

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

content/techniques/serialization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Note that the interceptor can be applied application-wide (as covered [here](htt
6161

6262
#### Using the SerializeOptions to transform plain objects to the class instance.
6363

64-
You could enforce transformations at the controller level by stating `@SerializeOptions({{ '{' }} type {{ ':' }} <CLASS_INSTANCE> {{ '}' }})` to transform all responses to the instance. Doing so will ensure that decorators on the class will always be applied, even if plain objects are returned. This allows for terser code, without the added verbosity of instantiating the class or calling `plainToInstance` repeatedly.
64+
You could enforce transformations at the controller level by stating `@SerializeOptions({{ '{' }} type {{ ':' }} <CLASS> {{ '}' }})` to transform all responses to the instance. Doing so will ensure that decorators on the class will always be applied, even if plain objects are returned. This allows for terser code, without the added verbosity of instantiating the class or calling `plainToInstance` repeatedly.
6565

6666
In this example, even though a plain js object was returned in both conditional statements, they will all be converted into `UserEntity` with annotated class-validator or class-transformer decorators applied.
6767

@@ -88,7 +88,7 @@ findOne(@Query() { id }: { id: number }): UserEntity {
8888
}
8989
```
9090

91-
> info **Hint** By stating the return type, we take advantage of Typescript to check if the plain js object conforms to the class shape.`plainToInstance`'s second argument does not check if the object has the same shape as the class instance (somewhat equivalent to typecasting), and could lead to bugs in your application.
91+
> info **Hint** By stating the expecting controller return type, we can take advantage of Typescript to check if the returned plain object conforms to the DTO/entity shape. `plainToInstance`' does not hint if the plain object conforms to the the DTO/entity class instance you are transforming it into (somewhat equivalent to typecasting). This could lead to bugs in your application.
9292
9393
#### Expose properties
9494

0 commit comments

Comments
 (0)