Skip to content

Commit c185beb

Browse files
docs: add some WIP docs files
1 parent e2d40c8 commit c185beb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Table of contents
22

33
- [Getting Started](pages/01-getting-started.md)
4+
- [Basic usage](pages/02-basis-usage.md)

docs/pages/02-basic-usage.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Basic usage
2+
3+
There are two main exported functions what can be used for transformations:
4+
5+
- `plainToClass` - transforms a plain object to an instance of the specified class constructor
6+
- `classToPlain` - transforms a _known_ class instance to a plain object
7+
8+
Both function transforms the source object to the target via applying the metadata registered by the decorators on
9+
the class definition. The four main decorators are:
10+
11+
- `@Expose` specifies how expose the given property on the plain object
12+
- `@Exclude` marks the property as skipped, so it won't show up in the transformation
13+
- `@Transform` allows specifying a custom transformation on the property via a custom handler
14+
- `@Type` decorator explicitly sets the type of the property, during the transformation `class-transformer` will attempt
15+
to create an instance of the specified type
16+
17+
You must always decorate all your properties with an `@Expose` or `@Exclude` decorator.
18+
19+
> **NOTE:** It's important to remember `class-transformer` will call the target type with am empty constructor, so if
20+
> you are using a type what requires special setup, you need to use a `@Transform` decorator and create the instance yourself.

0 commit comments

Comments
 (0)