2. 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.
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.
...
...
@@ -76,17 +55,14 @@
**Change Impacts**
1. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error will occur.
1. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error message will be displayed.
```ts
// ArkTS:ERROR Please define an explicit type, not any.
// ArkTS:WARN Please define an explicit type, not any.
@StateisLunar:any=false
```
2. If the data type of a state variable decorated by a state decorator is declared as **Date**, a build error will occur.
```ts
// ArkTS:ERROR The @State property 'selectedDate' cannot be a 'Date' object.
@StateselectedDate:Date=newDate('2021-08-08')
```
3. 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.
3. 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.
```ts
/* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type,
which are not allowed to be defined for state variable of a struct.*/
...
...
@@ -100,7 +76,6 @@ N/A
**Adaptation Guide**
1. Explicitly declare the data type for state variables decorated by state decorators.
2. 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.
3.
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:
```ts
...
...
@@ -115,7 +90,7 @@ N/A
Comply with the following rules when using constructors to initialize member variables:
| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **regular** | **@State** | **@Link** | **@Prop** | **@Provide** | **@Consume** | **@ObjectLink** |
@@ -125,7 +100,7 @@ Comply with the following rules when using constructors to initialize member var
| **@ObjectLink** | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported |
| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **@StorageLink** | **@StorageProp** | **@LocalStorageLink** | **@LocalStorageProp** |
@@ -144,7 +119,7 @@ Comply with the following rules when using constructors to initialize member var
**Change Impacts**
1.Variables decorated by **@LocalStorageLink** and **@LocalStorageProp** cannot be initialized from the parent component.
1.**@LocalStorageLink** and **@LocalStorageProp** variables cannot be initialized from the parent component. Otherwise, a build error message will be displayed.
```ts
@Entry
@Component
...
...
@@ -152,10 +127,10 @@ Comply with the following rules when using constructors to initialize member var
build(){
Column(){
Child({
/* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot
/* ArkTS:WARN Property 'simpleVarName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */
simpleVarName:1,
/* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot
/* ArkTS:WARN Property 'objectName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */
objectName:newClassA("x")
})
...
...
@@ -210,11 +185,11 @@ Comply with the following rules when using constructors to initialize member var
N/A
**Adaptation Guide**
1. When building a child component, do not perform the build on the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
1. When building a child component, do not assign values to the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
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.
2. For details about how to use **@ObjectLink**, see [@Observed and @ObjectLink](../../../application-dev/quick-start/arkts-observed-and-objectlink.md).
2. For details about how to use **@ObjectLink**, see [\@Observed and \@ObjectLink Decorators: Observing Attribute Changes in Nested Class Objects](../../../application-dev/quick-start/arkts-observed-and-objectlink.md).
## cl.arkui.3 Change of the onScrollBegin Event of the \<List> and \<Scroll> Components
...
...
@@ -227,12 +202,12 @@ The **onScrollBegin** event is deprecated and must be replaced with the **onScro
## cl.arkui.1 Restrictions on Data Type Declarations of State Variables
The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any**.
**Example**
```ts
// xxx.ets
@Entry
@Component
structDatePickerExample{
// Incorrect: @State isLunar: any = false
@StateisLunar:boolean=false
build(){
...
}
}
```
**Change Impacts**
If the data type of a state variable decorated by a state decorator is declared as **any**, a WARN-level (previously ERROR-level) build error will occur.
```ts
// ArkTS:ERROR Please define an explicit type, not any.
@StateisLunar:any=false
```
**Key API/Component Changes**
N/A
**Adaptation Guide**
Explicitly declare the data type for state variables decorated by state decorators.
## cl.arkui.2 Initialization Rules and Restrictions of Custom Components' Member Variables
**@LocalStorageLink** and **@LocalStorageProp** variables cannot be initialized from the parent component.
**Example**
```ts
letNextID:number=0;
@Observed
classClassA{
publicid:number;
publicc:number;
constructor(c:number){
this.id=NextID++;
this.c=c;
}
}
@Entry
@Component
structLocalStorageComponent{
build(){
Column(){
Child({
/* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */
simpleVarName:1,
/* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot
If **@LocalStorageLink** and **@LocalStorageProp** variables are initialized from the parent component, a WARN-level (previously ERROR-level) build error will occur.
**Key API/Component Changes**
N/A
**Adaptation Guide**
When building a child component, do not assign values to the variables by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
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.
## cl.arkui.1 Change in the Priority of alignContent and align Attributes for \<Stack>
Changed the priority of **alignContent** and **align** as follows:
API version 9 and earlier: The universal attribute **align** prevails.
API version 10 and later: The last set attribute prevails.
When two attributes provide the same functions, the last set attribute takes effect. This rule applies to **alignContent** and **align**, both of which set the alignment mode when used for the **\<Stack>** component.