HarmonyOS NEXT鸿蒙开发 ArkTS:联合类型(变量可以是多个类型) 作者:马育民 • 2025-09-08 15:19 • 阅读:10007 # 联合类型 ArkTS 中的变量,可以是 **多个类型** ### 声明 ``` let 变量名 : 类型1 | 类型2 = 值 ``` ### 例子 定义变量 `age` ,可以是 `number`、`string` 类型 ``` let age : number|string = 20 // 可以赋值数字 console.log("age:",age) // 也可以赋值字符串 age = "二十" console.log("age:",age) ``` 原文出处:http://malaoshi.top/show_1GW1pA7hCyaL.html