1# ArkUI Subsystem ChangeLog
2
3## cl.arkui.1 Restrictions on Data Type Declarations of State Variables
4
51. The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any** or **Date**.
6
7    Example:
8
9    ```ts
10    // xxx.ets
11    @Entry
12    @Component
13    struct DatePickerExample {
14      // Incorrect: @State isLunar: any = false
15      @State isLunar: boolean = false
16      // Incorrect: @State selectedDate: Date = new Date('2021-08-08')
17      private selectedDate: Date = new Date('2021-08-08')
18
19      build() {
20        Column() {
21          Button('Switch Calendar')
22            .margin({ top: 30 })
23            .onClick(() => {
24              this.isLunar = !this.isLunar
25            })
26          DatePicker({
27            start: new Date('1970-1-1'),
28            end: new Date('2100-1-1'),
29            selected: this.selectedDate
30          })
31            .lunar(this.isLunar)
32            .onChange((value: DatePickerResult) => {
33              this.selectedDate.setFullYear(value.year, value.month, value.day)
34              console.info('select current date is: ' + JSON.stringify(value))
35            })
36
37        }.width('100%')
38      }
39    }
40    ```
41
422. 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.
43
44    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.
45    For details about the definitions of **Length**, **ResourceStr**, and **ResourceColor**, see [Types](../../../application-dev/reference/arkui-ts/ts-types.md).
46
47    Example:
48
49    ```ts
50    // xxx.ets
51    @Entry
52    @Component
53    struct IndexPage {
54      // Incorrect: @State message: string | Resource = 'Hello World'
55      @State message: string = 'Hello World'
56      // Incorrect: @State message: ResourceStr = $r('app.string.hello')
57      @State resourceStr: Resource = $r('app.string.hello')
58
59      build() {
60        Row() {
61          Column() {
62            Text(`${this.message}`)
63              .fontSize(50)
64              .fontWeight(FontWeight.Bold)
65          }
66          .width('100%')
67        }
68        .height('100%')
69      }
70    }
71    ```
72
73    ![hello](../../../application-dev/quick-start/figures/hello.PNG)
74
75**Change Impact**
76
771. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error will occur.
78    ```ts
79    // ArkTS:ERROR Please define an explicit type, not any.
80    @State isLunar: any = false
81    ```
822. If the data type of a state variable decorated by a state decorator is declared as **Date**, a build error will occur.
83    ```ts
84    // ArkTS:ERROR The @State property 'selectedDate' cannot be a 'Date' object.
85    @State selectedDate: Date = new Date('2021-08-08')
86    ```
873. 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.
88    ```ts
89    /* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type,
90      which are not allowed to be defined for state variable of a struct.*/
91    @State message: ResourceStr = $r('app.string.hello')
92    ```
93
94**Key API/Component Changes**
95
96N/A
97
98**Adaptation Guide**
99
1001. Explicitly declare the data type for state variables decorated by state decorators.
1012. 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.
1023. 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:
103    ```ts
104    // Incorrect:
105    @State message: ResourceStr = $r('app.string.hello')
106    // Corrected:
107    @State resourceStr: Resource = $r('app.string.hello')
108    ```
109
110
111## cl.arkui.2 Initialization Rules and Restrictions of Custom Components' Member Variables
112
113Comply with the following rules when using constructors to initialize member variables:
114
115| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **regular** | **@State** | **@Link** | **@Prop** | **@Provide** | **@Consume** | **@ObjectLink** |
116|---------------------------------|----------------------------|------------|-----------|-----------|--------------|--------------|------------------|
117| **regular**                    | Supported                        | Supported        | Supported       | Supported       | Not supported           | Not supported           | Supported              |
118| **@State**                     | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
119| **@Link**                      | Not supported                         | Supported (1)     | Supported (1)    | Supported (1)    | Supported (1)       | Supported (1)       | Supported (1)           |
120| **@Prop**                      | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
121| **@Provide**                   | Supported                        | Supported        | Supported       | Supported       | Supported          | Supported          | Supported              |
122| **@Consume**                   | Not supported                         | Not supported         | Not supported        | Not supported        | Not supported           | Not supported           | Not supported               |
123| **@ObjectLink**                | Not supported                         | Not supported     | Not supported        | Not supported        | Not supported           | Not supported           | Not supported               |
124
125| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **@StorageLink** | **@StorageProp** | **@LocalStorageLink** | **@LocalStorageProp** |
126|------------------|------------------|------------------|-----------------------|------------------------|
127| **regular**                   | Supported              | Not supported               | Not supported                    | Not supported             |
128| **@State**                    | Supported              | Supported              | Supported                   | Supported                    |
129| **@Link**                     | Supported (1)           | Supported (1)           | Supported (1)                | Supported (1)                 |
130| **@Prop**                     | Supported              | Supported              | Supported                   | Supported                    |
131| **@Provide**                  | Supported              | Supported              | Supported                   | Supported                    |
132| **@Consume**                  | Not supported            | Not supported             | Not supported                 | Not supported                  |
133| **@ObjectLink**               | Not supported            | Not supported             | Not supported                 | Not supported                  |
134
135> **NOTE**
136>
137> **Supported (1)**: The dollar sign ($) must be used, for example, **this.$varA**.
138>
139> **regular**: refers to a regular variable that is not decorated by any decorator.
140
141**@StorageLink**, **@StorageProp**, **@LocalStorageLink**, and **@LocalStorageProp** variables cannot be initialized from the parent component.
142
143**Change Impact**
144
1451. Variables decorated by **@LocalStorageLink** and **@LocalStorageProp** cannot be initialized from the parent component.
146    ```ts
147    @Entry
148    @Component
149    struct LocalStorageComponent {
150        build() {
151            Column() {
152                Child({
153                  /* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot
154                    initialize here (forbidden to specify). */
155                  simpleVarName: 1,
156                  /* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot
157                    initialize here (forbidden to specify). */
158                  objectName: new ClassA("x")
159                })
160            }
161        }
162    }
163    @Component
164    struct Child {
165        @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0;
166        @LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA("x");
167        build() {}
168    }
169    ```
1702. 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**.
171    ```ts
172    let NextID : number = 0;
173
174    @Observed class ClassA {
175      public id : number;
176      public c: number;
177      constructor(c: number) {
178        this.id = NextID++;
179        this.c = c;
180      }
181    }
182
183    @Component
184    struct Child {
185      @ObjectLink varA : ClassA;
186      build() {
187        Row() {
188          Text('ViewA-' + this.varA.id)
189        }
190      }
191    }
192
193    @Component
194    struct Parent {
195      @Link linkValue: ClassA
196      build() {
197        Column() {
198          /* ArkTS:ERROR The @Link property 'linkValue' cannot be assigned to
199            the @ObjectLink property 'varA'.*/
200          Child({ varA: this.linkValue })
201        }
202      }
203    }
204    ```
205
206**Key API/Component Changes**
207
208N/A
209
210**Adaptation Guide**
2111. When building a child component, do not perform the build on the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
212
213  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.
214
2152. For details about how to use @ObjectLink, see @ObjectLink usage guide.
216
217
218## cl.arkui.LocalStorage.1 Return Type Change of the get API
219
220**Change Impact**
221
222Changed the return type from **get\<T>(propName: string): T** to **get<T>(propName: string): T | undefined**.
223
224No adaptation is needed.
225
226## cl.arkui.LocalStorage.2 Mandatory/Optional Change of the newValue Parameter in setOrCreate
227**Change Impact**
228
229API declaration before change:
230```js
231setOrCreate<T>(propName: string, newValue?: T): boolean
232```
233API declaration after change:
234```js
235setOrCreate<T>(propName: string, newValue: T): boolean
236```
237The **newValue** parameter becomes mandatory.
238If it is not specified when an application calls the API, the build will fail after the SDK is replaced.
239
240**Adaptation Guide**
241
242```js
243let storage = new LocalStorage();
244storage.setOrCreate('propA', 'hello');
245```
246## cl.arkui.LocalStorage.3 link Parameter and Return Type Changes
247**Change Impact**
248
249API declaration before change:
250```js
251link<T>(propName: string, linkUser?: T, subscribersName?: string): T
252```
253API declaration after change:
254```js
255link<T>(propName: string): SubscribedAbstractProperty<T>
256```
2571. The second and third parameters of the **link** API are reserved for internal use by the framework. Therefore, the API is changed to contain only one parameter.
2582. The return type **T** is changed to **SubscribedAbstractProperty**.
259
260**Adaptation Guide**
261
262```js
263let storage = new LocalStorage({"PropA": "47"});
264let linA = storage.link("PropA");
265linA.set(50);
266```
267
268## cl.arkui.LocalStorage.4 setAndLink Parameter and Return Type Changes
269**Change Impact**
270
271API declaration before change:
272```js
273setAndLink<T>(propName: string, defaultValue: T, linkUser?: T, subscribersName?: string): T
274```
275API declaration after change:
276```js
277setAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T>
278```
2791. The third and fourth parameters of the **setAndLink** API are reserved for internal use by the framework. Therefore, the API is changed to contain two parameters.
2802. The return type **T** is changed to **SubscribedAbstractProperty**.
281
282**Adaptation Guide**
283
284```js
285let storage = new LocalStorage({"PropA": "47"});
286let linA = storage.setAndLink("PropA", "48")
287linA.set(50);
288```
289
290## cl.arkui.LocalStorage.5 prop Parameter and Return Type Changes
291**Change Impact**
292
293API declaration before change:
294```js
295prop<T>(propName: string, propUser?: T, subscribersName?: string): T
296```
297API declaration after change:
298```js
299prop<S>(propName: string): SubscribedAbstractProperty<S>
300```
3011. The second and third parameters of the **prop** API are reserved for internal use by the framework. Therefore, the API is changed to contain only one parameter.
3022. The return type **T** is changed to **SubscribedAbstractProperty**.
303
304**Adaptation Guide**
305
306```js
307let storage = new LocalStorage({"PropA": "47"});
308let propA = storage.prop("PropA");
309propA.set(51); // one-way sync
310```
311
312## cl.arkui.LocalStorage.6 setAndProp Parameter and Return Type Changes
313**Change Impact**
314
315API declaration before change:
316```js
317setAndProp<T>(propName: string, defaultValue: T, propUser?: T, subscribersName?: string): T
318```
319API declaration after change:
320```js
321setAndProp<S>(propName: string, defaultValue: S): SubscribedAbstractProperty<S>
322```
3231. The third and fourth parameters of the **setAndProp** API are reserved for internal use by the framework. Therefore, the API is changed to contain two parameters.
3242. The return type **T** is changed to **SubscribedAbstractProperty**.
325
326**Adaptation Guide**
327
328```js
329let storage = new LocalStorage({"PropA": "47"});
330let propA = storage.setAndProp("PropA", "48");
331propA.set(51); // one-way sync
332```
333