10
0
e 3 сар өмнө
parent
commit
1947a5eefa

+ 0 - 5
14.ts/3.编译选项/demo3.js

@@ -1,5 +0,0 @@
-console.log("这是第三个");
-var a = 10;
-document.body.addEventListener('click', function () {
-    console.log("你好");
-});

+ 14 - 1
14.ts/3.编译选项/demo3.ts

@@ -2,4 +2,17 @@ console.log("这是第三个")
 let a = 10;
 document.body.addEventListener('click',()=> {
     console.log("你好")
-})
+})
+// document
+var box = document.getElementById("box");
+box?.addEventListener("click",()=> {
+    console.log("帽子")
+})
+function fn1(a:string) {
+    
+    return console.log(a)
+    // return console.log(this,a)
+}
+fn1("哈哈哈")
+fn1("你好")
+// fn1(33)

+ 39 - 0
14.ts/3.编译选项/dist/hello.js

@@ -0,0 +1,39 @@
+console.log("这是第三个");
+let a = 10;
+document.body.addEventListener('click', () => {
+    console.log("你好");
+});
+var box = document.getElementById("box");
+box === null || box === void 0 ? void 0 : box.addEventListener("click", () => {
+    console.log("帽子");
+});
+function fn1(a) {
+    return console.log(a);
+}
+fn1("哈哈哈");
+fn1("你好");
+console.log("第一个你好");
+let h;
+console.log("第二个");
+let www;
+www = 12;
+www = '12';
+System.register("src/demo5", [], function (exports_1, context_1) {
+    "use strict";
+    var mm;
+    var __moduleName = context_1 && context_1.id;
+    return {
+        setters: [],
+        execute: function () {
+            exports_1("mm", mm = '妹妹');
+            console.log("wuwuuwu");
+        }
+    };
+});
+console.log("hi,妹妹");
+let a1 = 2;
+function sayHello() {
+    return;
+    console.log("Hello, World!");
+}
+console.log("第四个");

+ 11 - 0
14.ts/3.编译选项/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="./dist/hello.js"></script>
+</body>
+</html>

+ 7 - 1
14.ts/3.编译选项/src/demo1.ts

@@ -1 +1,7 @@
-console.log("第一个你好")
+console.log("第一个你好")
+/***
+ * 今天是个好日子
+ * 心想的事儿 都能成
+ */
+let h;
+// h = 'yes';

+ 4 - 1
14.ts/3.编译选项/src/demo2.ts

@@ -1 +1,4 @@
-console.log("第二个")
+console.log("第二个")
+let www:any;
+www = 12;
+www = '12'

+ 2 - 0
14.ts/3.编译选项/src/demo5.ts

@@ -0,0 +1,2 @@
+export const mm = '妹妹';
+console.log("wuwuuwu")

+ 8 - 0
14.ts/3.编译选项/src/hi.js

@@ -0,0 +1,8 @@
+console.log("hi,妹妹");
+// const a = 1;
+// console.log(ar);
+let a1 = 2;
+function sayHello() {
+    return;
+  console.log("Hello, World!");
+}

+ 33 - 5
14.ts/3.编译选项/tsconfig.json

@@ -8,16 +8,44 @@
         // "./src/**/*"
     // ],
     // 排除
-    "exclude": [
-        "./src/**/*"
-    ],
+    // "exclude": [
+    //     "./src/**/*"
+    // ],
     // "extends" 继承
     // files 文件
     // 编辑选项
     "compilerOptions": {
         // 模板 => Node
-        // "moduleResolution": "Node",
+        "moduleResolution": "Node",
         // target规定了 ts编译成那个js的版本:'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'
-        "target": "ES5"
+        "target": "ES2015",
+        // 模块 "CommonJS", "AMD", "System", "UMD", "ES6", "ES2015", "ES2020", "ESNext", "None", "ES2022", "Node16", "NodeNext", "Preserve".
+        "module": "system",
+        // lib 规定允许使用什么库
+        "lib": ["dom"],
+        // outDir 规定将编译后的文件具体放在那个位置
+        "outDir": "./dist",
+        // outFile 将编译后的所有文件放在一个文件夹下
+        "outFile": "./dist/hello.js",
+        //allowJs 允许编译js文件
+        "allowJs": true,
+        // checkJs 檢查js文件是否符合编译规范
+        "checkJs": true,
+        // removeComments 是否移除注释
+        "removeComments": true,
+        // noEmitOnError 规定错误是否允许编译
+        // "noEmitOnError": true,
+        // noEmit 规定文件是否被编译
+        // "noEmit": true
+        // 是否开启严格模式
+        "strict": false
+        // alwaysStrict 编译后的文件是否按照严格模式执行
+        // "alwaysStrict": false,
+        // // 不允许数据默认是any类型
+        // "noImplicitAny": true,
+        // // 规定是否允许使用this
+        // "noImplicitThis": true,
+        // // 检查是否为空
+        // "strictNullChecks": true
     }
 }

+ 2 - 1
14.ts/归纳.md

@@ -3,4 +3,5 @@
 ## 1.全局安装ts: npm install -g typescript
 ## 2.检查是否安装成功:tsc -v(version)
 ## 3.创建ts文件:名字(英文/英文+数字).ts
-## 4.编译ts命令:tsc 文件名称 => 将ts文件编译成js文件 浏览器不识别ts文件
+## 4.编译ts命令:tsc 文件名称 => 将ts文件编译成js文件 浏览器不识别ts文件
+## 5.模块化就是严格模式