数据类型
| 关键字 |
描述 |
| :string |
字符串 |
| :[type, type] |
元组(已知数量和类型的数组) |
| :number |
数字 |
| :boolean |
布尔 |
| :Array |
数组 |
| :void |
方法返回值的类型 |
| 反引号(`)来定义字符串的多行文本和内嵌表达式。 |
|
代码实现
class Senior {
MyName: string = "李田所";
BaseInfo: [number, string] = [24, "学生"];
Height: number = 174;
Exercise: boolean = true;
Arr: Array<number> = [1, 1, 4, 5, 1, 4];
Cry(): void {
console.log("哼啊啊啊啊啊啊")
};
Introduce(): void {
console.log(`姓名:${this.MyName}`)
console.log(`${this.BaseInfo[0]}岁`)
console.log(`是${this.BaseInfo[1]}`)
console.log(`身高${this.Height}`)
console.log(`在健身吗:${this.Exercise}`)
var x; for (x in this.Arr) { console.log(this.Arr[x]); }
this.Cry();
};
}
var mySenior = new Senior();
mySenior.Introduce();
执行结果
姓名:李田所
24岁
是学生
身高174
在健身吗:true
1
1
4
5
1
4
哼啊啊啊啊啊啊