1# \@Type Decorator: Marking the Types of the Class Property
2
3To avoid losing complex types of the properties when serializing classes, you can use the \@Type Decorator to decorate class.
4
5>**NOTE**
6>
7>\@Type is supported since API version 12.
8>
9>State management V2 is still under development, and some features may be incomplete or not always work as expected.
10
11
12## Overview
13
14\@Type marks class properties to avoid losing type information during class property serialization, facilitating class deserialization.
15
16
17## Decorator Description
18
19| \@Type Decorator| Description|
20| ------------------- | ------------------------------------------------------------ |
21| Parameter| Type.|
22| Allowed type| Object class and embedded types such as Array, Date, Map, and Set.|
23
24
25## Constraints
26
271. It can be used only in class.
28
292. Types such as collections.Set and collections.Map are not supported.
30
313. Non-buildin types, such as native PixelMap, NativePointer, and ArrayList types, are not supported.
32
334. Simple types such as string, number, and boolean, are not supported.
34
35## When to Use
36
37### Access Persistent Data
38
39Data page
40```ts
41import { Type } from '@kit.ArkUI';
42
43// Data center
44@ObservedV2
45class SampleChild {
46  @Trace p1: number = 0;
47  p2: number = 10;
48}
49
50@ObservedV2
51export class Sample {
52  // Complex objects need to be decorated by @Type to ensure successful serialization.
53  @Type(SampleChild)
54  @Trace f: SampleChild = new SampleChild();
55}
56```
57
58Page
59```ts
60import { PersistenceV2 } from '@kit.ArkUI';
61import { Sample } from '../Sample';
62
63@Entry
64@ComponentV2
65struct Page {
66  prop: Sample = PersistenceV2.connect(Sample, () => new Sample())!;
67
68  build() {
69    Column() {
70      Text(`Page1 add 1 to prop.p1: ${this.prop.f.p1}`)
71        .fontSize(30)
72        .onClick(() => {
73          this.prop.f.p1++;
74        })
75    }
76  }
77}
78```
79