1e41f4b71Sopenharmony_ci# ArkUI Subsystem ChangeLog
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## cl.arkui.1 Restrictions on Data Type Declarations of State Variables
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci1. The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any** or **Date**.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci    Example:
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci    ```ts
10e41f4b71Sopenharmony_ci    // xxx.ets
11e41f4b71Sopenharmony_ci    @Entry
12e41f4b71Sopenharmony_ci    @Component
13e41f4b71Sopenharmony_ci    struct DatePickerExample {
14e41f4b71Sopenharmony_ci      // Incorrect: @State isLunar: any = false
15e41f4b71Sopenharmony_ci      @State isLunar: boolean = false
16e41f4b71Sopenharmony_ci      // Incorrect: @State selectedDate: Date = new Date('2021-08-08')
17e41f4b71Sopenharmony_ci      private selectedDate: Date = new Date('2021-08-08')
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci      build() {
20e41f4b71Sopenharmony_ci        Column() {
21e41f4b71Sopenharmony_ci          Button('Switch Calendar')
22e41f4b71Sopenharmony_ci            .margin({ top: 30 })
23e41f4b71Sopenharmony_ci            .onClick(() => {
24e41f4b71Sopenharmony_ci              this.isLunar = !this.isLunar
25e41f4b71Sopenharmony_ci            })
26e41f4b71Sopenharmony_ci          DatePicker({
27e41f4b71Sopenharmony_ci            start: new Date('1970-1-1'),
28e41f4b71Sopenharmony_ci            end: new Date('2100-1-1'),
29e41f4b71Sopenharmony_ci            selected: this.selectedDate
30e41f4b71Sopenharmony_ci          })
31e41f4b71Sopenharmony_ci            .lunar(this.isLunar)
32e41f4b71Sopenharmony_ci            .onChange((value: DatePickerResult) => {
33e41f4b71Sopenharmony_ci              this.selectedDate.setFullYear(value.year, value.month, value.day)
34e41f4b71Sopenharmony_ci              console.info('select current date is: ' + JSON.stringify(value))
35e41f4b71Sopenharmony_ci            })
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci        }.width('100%')
38e41f4b71Sopenharmony_ci      }
39e41f4b71Sopenharmony_ci    }
40e41f4b71Sopenharmony_ci    ```
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci    ![datePicker](../../../application-dev/reference/arkui-ts/figures/datePicker.gif)
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci2. The data type declaration of the **@State**, **@Provide**, **@Link**, or **@Consume** decorated state variables can consist of only one of the primitive data types or reference data types.
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci    The **Length**, **ResourceStr**, and **ResourceColor** types are combinations of primitive data types or reference data types. Therefore, they cannot be used by the aforementioned types of state variables.
47e41f4b71Sopenharmony_ci    For details about the definitions of **Length**, **ResourceStr**, and **ResourceColor**, see [Types](../../../application-dev/reference/arkui-ts/ts-types.md).
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci    Example:
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci    ```ts
52e41f4b71Sopenharmony_ci    // xxx.ets
53e41f4b71Sopenharmony_ci    @Entry
54e41f4b71Sopenharmony_ci    @Component
55e41f4b71Sopenharmony_ci    struct IndexPage {
56e41f4b71Sopenharmony_ci      // Incorrect: @State message: string | Resource = 'Hello World'
57e41f4b71Sopenharmony_ci      @State message: string = 'Hello World'
58e41f4b71Sopenharmony_ci      // Incorrect: @State message: ResourceStr = $r('app.string.hello')
59e41f4b71Sopenharmony_ci      @State resourceStr: Resource = $r('app.string.hello')
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci      build() {
62e41f4b71Sopenharmony_ci        Row() {
63e41f4b71Sopenharmony_ci          Column() {
64e41f4b71Sopenharmony_ci            Text(`${this.message}`)
65e41f4b71Sopenharmony_ci              .fontSize(50)
66e41f4b71Sopenharmony_ci              .fontWeight(FontWeight.Bold)
67e41f4b71Sopenharmony_ci          }
68e41f4b71Sopenharmony_ci          .width('100%')
69e41f4b71Sopenharmony_ci        }
70e41f4b71Sopenharmony_ci        .height('100%')
71e41f4b71Sopenharmony_ci      }
72e41f4b71Sopenharmony_ci    }
73e41f4b71Sopenharmony_ci    ```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci    ![hello](../../../application-dev/quick-start/figures/hello.PNG)
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**Change Impacts**
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci1. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error will occur.
80e41f4b71Sopenharmony_ci    ```ts
81e41f4b71Sopenharmony_ci    // ArkTS:ERROR Please define an explicit type, not any.
82e41f4b71Sopenharmony_ci    @State isLunar: any = false
83e41f4b71Sopenharmony_ci    ```
84e41f4b71Sopenharmony_ci2. If the data type of a state variable decorated by a state decorator is declared as **Date**, a build error will occur.
85e41f4b71Sopenharmony_ci    ```ts
86e41f4b71Sopenharmony_ci    // ArkTS:ERROR The @State property 'selectedDate' cannot be a 'Date' object.
87e41f4b71Sopenharmony_ci    @State selectedDate: Date = new Date('2021-08-08')
88e41f4b71Sopenharmony_ci    ```
89e41f4b71Sopenharmony_ci3. If the data type of a **@State**, **@Provide**, **@Link**, and or **@Consume** decorated state variable is Length, **ResourceStr**, or **ResourceColor**, a build error will occur.
90e41f4b71Sopenharmony_ci    ```ts
91e41f4b71Sopenharmony_ci    /* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type,
92e41f4b71Sopenharmony_ci      which are not allowed to be defined for state variable of a struct.*/
93e41f4b71Sopenharmony_ci    @State message: ResourceStr = $r('app.string.hello')
94e41f4b71Sopenharmony_ci    ```
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**Key API/Component Changes**
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ciN/A
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**Adaptation Guide**
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci1. Explicitly declare the data type for state variables decorated by state decorators.
103e41f4b71Sopenharmony_ci2. If a state variable decorated by a state decorator uses the **Date** object, change it to a regular variable – a variable not decorated by any decorator.
104e41f4b71Sopenharmony_ci3. Adapt the **@State**, **@Provide**, **@Link**, and **@Consume** decorated variables based on the following code snippet so that they do not use the **Length(string|number|Resource)**, **ResourceStr(string|Resource)**, and **ResourceColor(string|number|Color|Resource)** types:
105e41f4b71Sopenharmony_ci    
106e41f4b71Sopenharmony_ci    ```ts
107e41f4b71Sopenharmony_ci    // Incorrect:
108e41f4b71Sopenharmony_ci    @State message: ResourceStr = $r('app.string.hello')
109e41f4b71Sopenharmony_ci    // Corrected:
110e41f4b71Sopenharmony_ci    @State resourceStr: Resource = $r('app.string.hello')
111e41f4b71Sopenharmony_ci    ```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci## cl.arkui.2 Initialization Rules and Restrictions of Custom Components' Member Variables
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ciComply with the following rules when using constructors to initialize member variables:
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **regular** | **@State** | **@Link** | **@Prop** | **@Provide** | **@Consume** | **@ObjectLink** |
118e41f4b71Sopenharmony_ci|---------------------------------|----------------------------|------------|-----------|-----------|--------------|--------------|------------------|
119e41f4b71Sopenharmony_ci| **regular**                    | Supported                        | Supported        | Supported       | Supported       | Not supported           | Not supported           | Supported              |
120e41f4b71Sopenharmony_ci| **@State**                     | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
121e41f4b71Sopenharmony_ci| **@Link**                      | Not supported                         | Supported (1)     | Supported (1)    | Supported (1)    | Supported (1)       | Supported (1)       | Supported (1)           |
122e41f4b71Sopenharmony_ci| **@Prop**                      | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
123e41f4b71Sopenharmony_ci| **@Provide**                   | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
124e41f4b71Sopenharmony_ci| **@Consume**                   | Not supported                         | Not supported         | Not supported        | Not supported        | Not supported           | Not supported           | Not supported               |
125e41f4b71Sopenharmony_ci| **@ObjectLink**                | Not supported                         | Not supported     | Not supported        | Not supported        | Not supported           | Not supported           | Not supported               |
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **@StorageLink** | **@StorageProp** | **@LocalStorageLink** | **@LocalStorageProp** |
128e41f4b71Sopenharmony_ci|------------------|------------------|------------------|-----------------------|------------------------|
129e41f4b71Sopenharmony_ci| **regular**                   | Supported              | Not supported               | Not supported                    | Not supported             |
130e41f4b71Sopenharmony_ci| **@State**                    | Supported              | Supported              | Supported                   | Supported                    |
131e41f4b71Sopenharmony_ci| **@Link**                     | Supported (1)           | Supported (1)           | Supported (1)                | Supported (1)                 |
132e41f4b71Sopenharmony_ci| **@Prop**                     | Supported              | Supported              | Supported                   | Supported                    |
133e41f4b71Sopenharmony_ci| **@Provide**                  | Supported              | Supported              | Supported                   | Supported                    |
134e41f4b71Sopenharmony_ci| **@Consume**                  | Not supported            | Not supported             | Not supported                 | Not supported                  |
135e41f4b71Sopenharmony_ci| **@ObjectLink**               | Not supported            | Not supported             | Not supported                 | Not supported                  |
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci> **NOTE**
138e41f4b71Sopenharmony_ci>
139e41f4b71Sopenharmony_ci> **Supported (1)**: The dollar sign ($) must be used, for example, **this.$varA**.
140e41f4b71Sopenharmony_ci>
141e41f4b71Sopenharmony_ci> **regular**: refers to a regular variable that is not decorated by any decorator.
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**@StorageLink**, **@StorageProp**, **@LocalStorageLink**, and **@LocalStorageProp** variables cannot be initialized from the parent component.
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**Change Impacts**
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci1. Variables decorated by **@LocalStorageLink** and **@LocalStorageProp** cannot be initialized from the parent component.
148e41f4b71Sopenharmony_ci    ```ts
149e41f4b71Sopenharmony_ci    @Entry
150e41f4b71Sopenharmony_ci    @Component
151e41f4b71Sopenharmony_ci    struct LocalStorageComponent {
152e41f4b71Sopenharmony_ci        build() {
153e41f4b71Sopenharmony_ci            Column() {
154e41f4b71Sopenharmony_ci                Child({
155e41f4b71Sopenharmony_ci                  /* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot
156e41f4b71Sopenharmony_ci                    initialize here (forbidden to specify). */
157e41f4b71Sopenharmony_ci                  simpleVarName: 1,
158e41f4b71Sopenharmony_ci                  /* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot
159e41f4b71Sopenharmony_ci                    initialize here (forbidden to specify). */
160e41f4b71Sopenharmony_ci                  objectName: new ClassA("x")
161e41f4b71Sopenharmony_ci                })
162e41f4b71Sopenharmony_ci            }
163e41f4b71Sopenharmony_ci        }
164e41f4b71Sopenharmony_ci    }
165e41f4b71Sopenharmony_ci    @Component
166e41f4b71Sopenharmony_ci    struct Child {
167e41f4b71Sopenharmony_ci        @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0;
168e41f4b71Sopenharmony_ci        @LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA("x");
169e41f4b71Sopenharmony_ci        build() {}
170e41f4b71Sopenharmony_ci    }
171e41f4b71Sopenharmony_ci    ```
172e41f4b71Sopenharmony_ci2. The **@ObjectLink** decorated variable cannot be directly initialized from a decorated variable in the parent component. The source of the parent component must be an array item or object attribute decorated by **@State**, **@Link**, **@Provide**, **@Consume**, or **@ObjectLink**.
173e41f4b71Sopenharmony_ci    ```ts
174e41f4b71Sopenharmony_ci    let NextID : number = 0;
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci    @Observed class ClassA {
177e41f4b71Sopenharmony_ci      public id : number;
178e41f4b71Sopenharmony_ci      public c: number;
179e41f4b71Sopenharmony_ci      constructor(c: number) {
180e41f4b71Sopenharmony_ci        this.id = NextID++;
181e41f4b71Sopenharmony_ci        this.c = c;
182e41f4b71Sopenharmony_ci      }
183e41f4b71Sopenharmony_ci    }
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci    @Component
186e41f4b71Sopenharmony_ci    struct Child {
187e41f4b71Sopenharmony_ci      @ObjectLink varA : ClassA;
188e41f4b71Sopenharmony_ci      build() {
189e41f4b71Sopenharmony_ci        Row() {
190e41f4b71Sopenharmony_ci          Text('ViewA-' + this.varA.id)
191e41f4b71Sopenharmony_ci        }
192e41f4b71Sopenharmony_ci      }
193e41f4b71Sopenharmony_ci    }
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci    @Component
196e41f4b71Sopenharmony_ci    struct Parent {
197e41f4b71Sopenharmony_ci      @Link linkValue: ClassA
198e41f4b71Sopenharmony_ci      build() {
199e41f4b71Sopenharmony_ci        Column() {
200e41f4b71Sopenharmony_ci          /* ArkTS:ERROR The @Link property 'linkValue' cannot be assigned to
201e41f4b71Sopenharmony_ci            the @ObjectLink property 'varA'.*/
202e41f4b71Sopenharmony_ci          Child({ varA: this.linkValue })
203e41f4b71Sopenharmony_ci        }
204e41f4b71Sopenharmony_ci      }
205e41f4b71Sopenharmony_ci    }
206e41f4b71Sopenharmony_ci    ```
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci**Key API/Component Changes**
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ciN/A
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci**Adaptation Guide**
213e41f4b71Sopenharmony_ci1. When building a child component, do not perform the build on the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci   To change these variables from the parent component, use the API provided by the **LocalStorage** (such as the **set** API) to assign values to them.
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci2. For details about how to use **@ObjectLink**, see [@Observed and @ObjectLink](../../../application-dev/quick-start/arkts-observed-and-objectlink.md).
218