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