From 354ccbf2a7bfea54e8c774c9a7c564b3a4856236 Mon Sep 17 00:00:00 2001 From: lihong Date: Thu, 20 Oct 2022 14:51:34 +0800 Subject: [PATCH] lihong67@huawei.com Add restrictions on the use of status variables. Signed-off-by: lihong Change-Id: I1ed1092a06c44fc6cc5f7befa7d6452b87d88a44 --- .../v3.2-beta3/changelog-v3.2-beta3.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zh-cn/release-notes/api-change/v3.2-beta3/changelog-v3.2-beta3.md b/zh-cn/release-notes/api-change/v3.2-beta3/changelog-v3.2-beta3.md index 48b3fb3ed9..411ee5c31b 100644 --- a/zh-cn/release-notes/api-change/v3.2-beta3/changelog-v3.2-beta3.md +++ b/zh-cn/release-notes/api-change/v3.2-beta3/changelog-v3.2-beta3.md @@ -172,6 +172,41 @@ FA模型下的公共模块变量共享之前是作为需求交付的,在中间 无 +### 状态变量多种数据类型声明使用限制。 + +状态变量比如@State、@Provide、 @Link和@Consume等,定义数据类型时,只能同时由简单数据类型或对象引用数据类型其中一种构成。 + +示例: + +```ts +@Entry +@Component +struct Index { + //错误写法: @State message: string | Resource = 'Hello World' + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(`${ this.message }`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} +``` + +**变更影响** + +当定义的状态变量类型中同时包含简单类型和对象引用数据类型时,编译报错提示不支持。 + +**关键的接口/组件变更** + +当定义的状态变量类型中同时包含简单类型和对象引用数据类型时,需修改为只含有其中一种,如上述示例代码所示。 + ## 全球化子系统 ### 针对color.json中颜色值,增加合法性校验 -- GitLab