zheng 1 week ago
parent
commit
ad5eae8d42

+ 0 - 1
11.ts/面向对象/dist/1.类.js

@@ -1,4 +1,3 @@
-"use strict";
 /**
  * 类 通过class定义
  * tsc -w

+ 0 - 1
11.ts/面向对象/dist/2.构造函数和this.js

@@ -1,4 +1,3 @@
-"use strict";
 // 构造函数
 // function fn1() {
 // };

+ 0 - 1
11.ts/面向对象/dist/3.继承.js

@@ -1,4 +1,3 @@
-"use strict";
 // function fn1() {}
 // fn1()
 // 立即执行函数

+ 0 - 1
11.ts/面向对象/dist/4.super.js

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     class Animal {
         constructor(name, sex) {

+ 0 - 1
11.ts/面向对象/dist/5.接口.js

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     class Person2 {
         constructor(name, age, color) {

+ 0 - 1
11.ts/面向对象/dist/6.属性的封装.js

@@ -1,4 +1,3 @@
-"use strict";
 (function () {
     class Person {
         constructor(name, age, color) {

+ 33 - 0
11.ts/面向对象/dist/7.泛型.js

@@ -0,0 +1,33 @@
+(function () {
+    // 泛型:先用字符去指代未知类型 使用时 传入具体的类型
+    function fn3(x) {
+        return x;
+    }
+    fn3(12);
+    fn3("12");
+    // function fn4<T extends number | string, K extends number | string>(x: T, y: K): number | string {
+    //     return x + y;
+    // }
+    function fn4(x, y) {
+        return x + y;
+    }
+    function fn5(x, y) {
+        return [x, y];
+    }
+    fn5(3, '43');
+    const res = fn4(3, '23');
+    console.log(res, '22222');
+    // 严格按照接口格式传参
+    // 函数中泛型继承接口
+    function fn6(a) {
+        return a;
+    }
+    fn6({ jump: 'aa' });
+    // 类中泛型继承接口
+    class Ending {
+        constructor(name) {
+            this.name = name;
+        }
+    }
+    let e = new Ending({ jump: 'aa' });
+})();

+ 1 - 1
11.ts/面向对象/dist/index.html

@@ -6,6 +6,6 @@
     <title>Document</title>
 </head>
 <body>
-    <script src="./6.属性的封装.js"></script>
+    <script src="./7.泛型.js"></script>
 </body>
 </html>

+ 40 - 0
11.ts/面向对象/src/7.泛型.ts

@@ -0,0 +1,40 @@
+(function () {
+    // 泛型:先用字符去指代未知类型 使用时 传入具体的类型
+    function fn3<T>(x: T): T {
+        return x;
+    }
+    fn3(12);
+    fn3<string>("12");
+
+    // function fn4<T extends number | string, K extends number | string>(x: T, y: K): number | string {
+    //     return x + y;
+    // }
+    function fn4<T, K>(x: T, y: K): string | number {
+        return (x as number) + (y as string)
+    }
+
+    function fn5<T, K>(x: T, y: K): [T, K] {
+        return [x, y];
+    }
+    fn5(3, '43')
+    const res = fn4(3, '23');
+    console.log(res, '22222')
+
+    interface happy {
+        jump: string
+    }
+    // 严格按照接口格式传参
+    // 函数中泛型继承接口
+    function fn6<T extends happy>(a:T):T {
+        return a;
+    }
+    fn6({jump: 'aa'})
+    // 类中泛型继承接口
+    class Ending<T extends happy>{
+        name:T;
+        constructor(name:T) {
+            this.name = name;
+        }
+    }
+    let e = new Ending({jump: 'aa'})
+})()

+ 2 - 2
11.ts/面向对象/tsconfig.json

@@ -7,9 +7,9 @@
         "module": "ES2015",
         "lib": ["dom","ES2015"],
         "outDir": "./dist",
-        "strict": true,
+        "strict": false,
         "noImplicitThis": false,
         "noImplicitAny": false,
-        "noEmitOnError": true
+        // "noEmitOnError": true
     }
 }