|
@@ -0,0 +1,48 @@
|
|
|
+(function() {
|
|
|
+ type happy = {
|
|
|
+ name: string,
|
|
|
+ age: number,
|
|
|
+ }
|
|
|
+ // 类型别名 定义数据
|
|
|
+ const obj:happy = {
|
|
|
+ name: "孙悟空",
|
|
|
+ age: 20,
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 接口 换而言之 也是一种定义数据的规范
|
|
|
+ *
|
|
|
+ */
|
|
|
+ interface sad {
|
|
|
+ name: string,
|
|
|
+ age: number,
|
|
|
+ }
|
|
|
+
|
|
|
+ interface sad {
|
|
|
+ sex: string
|
|
|
+ }
|
|
|
+
|
|
|
+ // 继承 extends
|
|
|
+ // 接口 interface implements
|
|
|
+ class Person implements sad {
|
|
|
+ // num: number;
|
|
|
+ // constructor(num: number) {
|
|
|
+ // this.num = num;
|
|
|
+ // }
|
|
|
+ name: string;
|
|
|
+ age: number;
|
|
|
+ num: number;
|
|
|
+ sex: string;
|
|
|
+ constructor(name: string, age: number, sex: string,num:number) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ this.num = num;
|
|
|
+ this.sex = sex;
|
|
|
+ }
|
|
|
+ say() {
|
|
|
+ console.log(this.name, this.age, this.num, this.sex,'我是个好人');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ let a = new Person("猪八戒", 20, "男",1);
|
|
|
+ a.say()
|
|
|
+})()
|