|
|
@@ -0,0 +1,39 @@
|
|
|
+(function () {
|
|
|
+ /**
|
|
|
+ * 类型别名 接口区别
|
|
|
+ * 接口:偏向 对象/结构的定义 可扩展 可合并
|
|
|
+ * 类型别名:偏向于任意类型 联合/交叉类型 简单的别名
|
|
|
+ * */
|
|
|
+
|
|
|
+ // 接口:定义数据类型的规范
|
|
|
+ // interface status = 1|2|3;
|
|
|
+ // 接口声明
|
|
|
+ interface xxx {
|
|
|
+ name: string,
|
|
|
+ age: number,
|
|
|
+ address: string,
|
|
|
+ sex: string
|
|
|
+ }
|
|
|
+ interface xxx {
|
|
|
+ sex: string
|
|
|
+ }
|
|
|
+ // 类实现接口 需要继承
|
|
|
+ // 类型约束
|
|
|
+ class List implements xxx {
|
|
|
+ name: string;
|
|
|
+ age: number;
|
|
|
+ address: string;
|
|
|
+ // sex: string;
|
|
|
+ x: string;
|
|
|
+ constructor(name: string, age: number, address: string, sex: string, x: string) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ this.address = address;
|
|
|
+ this.sex = sex;
|
|
|
+ this.x = x;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let x = new List('图图', 3, '上海', '12');
|
|
|
+ console.log(x);
|
|
|
+
|
|
|
+})()
|