# TypeScriptStudent **Repository Path**: javafdx/type-script-student ## Basic Information - **Project Name**: TypeScriptStudent - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-05 - **Last Updated**: 2021-08-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### npm init tsc --init (npm install -g typescript;安装完成便可以通过 tsc 命令将ts文件编译成js文件) npm install ts-node -D 或者 npm install ts-node --save-dev npm install typescript -D npm install superagent --save (爬取网页依赖) npm install cheerio --save (分析网页) ### 已声明“superagent”,但从未读取其值。ts(6133) 无法找到模块“superagent”的声明文件。“e:/TypescriptDemo/爬虫demo/node_modules/superagent/lib/node/index.js”隐式拥有 "any" 类型。 尝试使用 `npm i --save-dev @types/superagent` (如果存在),或者添加一个包含 `declare module 'superagent';` 的新声明(.d.ts)文件 在ts文件中引入js 文件就会报错 ts-->.d.ts 翻译文件-->js ### build 1. 编译成js文件 "build": "tsc", 2. 配置输出文件 tsconfig.json "outDir": "./build", ### 热更新(二合一) 1. 监听ts文件变化-->生成j's "build": "tsc -w", 2. 监听js文件变化,会执行命令(省去 了node-ts编译过程) npm intsall nodemon -D "start": "nodemon node ./build/crowller.js" 3. 忽略以下文件 "nodemonConfig": { "ignore": ["data/*"] } ### 单个依赖完成热更新 npm install concurrently -D "dev:build": "tsc -w", "dev:start": "nodemon node ./build/crowller.js", "dev": "concurrently npm run dev:build & npm run dev:start" // "dev": "concurrently npm:dev:*" ### 解释tsconfig.json文件 // "removeComments": true, // 是否显示注释 tcs命令--会自动编译根目录下边的ts文件 ------------------- "include": ["./demo.ts"], // 指定编译哪些文件或者"files": ["./"] "exclude": ["./demo.ts"], // 不编译的文件 ----------------------- // "noImplicitAny": false, // 定义一个变量,不指定any类型也可以 function abc (name) {} name不用指明name: any ------------------- // "strictNullChecks": false, // 不强制检测null类型 const teacher: string = null; ------------------------ "outDir": "./build", // 输出 "rootDir": "./", // 编译 ------------------------ "incremental": true, // 增量编译(会生成一个文件。记录,已经编译过的文件就不在编译) --------------------------- "target": "es5", // 把ts文件编译成es5的语法风格 -------------------------- "allowJs": true, // 把js文件编译成es5语法 ------------------------- "checkJs": true, // 检测js 语法是否错误 ------------------------- "noUnusedLocals": true, // 检测定义但是没有用到的变量,提示错误 "noUnusedParameters": true, // 检测函数参数 ### 命名空间 "outDir": "./dist", "rootDir": "./src" // "outFile": "./", 把所有文件输出到一个文件中 "outFile": "./build/page.js", 然后再修改 原来"module": "commonjs", "module": "amd" // 模块规范 // 表明依赖关系 /// ### 使用Parcel打包TS代码 npm install parcel@next -D "dev": "parcel ./src/index.html"