|
|
@@ -0,0 +1,39 @@
|
|
|
+(function () {
|
|
|
+ // 接口:定义数据的一种规范
|
|
|
+ interface sad {
|
|
|
+ name: string,
|
|
|
+ age: number
|
|
|
+ }
|
|
|
+ interface sad {
|
|
|
+ sex: string
|
|
|
+ }
|
|
|
+
|
|
|
+ // 联合类型
|
|
|
+ type x1 = string | number;
|
|
|
+
|
|
|
+ // interface 可以使用extends继承接口
|
|
|
+ // type 可以使用联合类型和交叉类型
|
|
|
+
|
|
|
+
|
|
|
+ class Person implements sad {
|
|
|
+ name: string;
|
|
|
+ age: number;
|
|
|
+ sex: string;
|
|
|
+ constructor(name: string, age: number, sex: string) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age
|
|
|
+ this.sex = sex;
|
|
|
+ }
|
|
|
+ say() {
|
|
|
+ console.log('我叫' + this.name + ',今年' + this.age + '岁')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let p = new Person("图图", 3, '男');
|
|
|
+ console.log(p, 'p');
|
|
|
+ p.say();
|
|
|
+
|
|
|
+
|
|
|
+ // type x1 = {
|
|
|
+ // sex: string
|
|
|
+ // }
|
|
|
+})()
|