TypeScript是javaScript的一个超集
ArkTS基于TypeScript语言,拓展了声明式UI,状态管理,并发任务等能力
字符串
let name:string= "harmonyOS";
数组
let list1:number[] = [1,2,3];
let list2:Array<number> = [1,2,3];
元组-
let x:[string:number];
x =["huawei",10] //注释
x = [10,'huawei']; // 传参必须和规定的类型顺序一致
枚举
enum Color{Red,Green,Blue};
let c:Color =Color.Green // 定义颜色
unknown
let notSure:unknown = 3;
notSure = 'maybe a string instead';
notSure = false;
void
function test():void{
console.log('The func is void')
}
null 和undefined
let u:undefined = undefined;
let n :null =null;=
联合类型
let myFavoriteNumber :string|number;
myFavoriteNumber = 'eleven';
myFavoriteNumber = 11;