1. tsconfig.json https://www.tslang.cn/docs/handbook/tsconfig-json.html
  2. tsc —init,自动产生tsconfig.json
    1. 初始化的tsconfig.json无需修改,增加”allowJs”: true选项
  3. file 属性
  4. include & exclude属性
    1. 指定一个文件glob匹配模式列表
  5. extends 继承
  6. 一个目录下存在一个tsconfig.json文件,那这个目录是TypeScript项目的根目录
  7. —project(或-p)指定一个包含tsconfig.json文件的目录

tsconfig.json

  1. {
  2. "compilerOptions": {
  3. "noImplicitAny": false, // 不需要显式地声明变量的类型any
  4. // 编译后的目标javascript版本,ES5, ES6/ES2015,16,17,18,19,ES2020, ESNext
  5. "target": "es5", // 编译后代码的ES版本,还有es3es2105
  6. "lib": [
  7. "dom", // document.getElementById("root")
  8. "dom.iterable",
  9. "esnext"
  10. ],
  11. "removeComments": true,
  12. "noImplicitAny": true,
  13. "preserveConstEnums": true,
  14. "allowJs": true, // 允许混合编译JavaScript文件
  15. "skipLibCheck": true,
  16. // 允许我们使用commonjs的方式import默认文件, import React from 'react'
  17. "esModuleInterop": true,
  18. // "esModuleInterop": false, import * as React from 'react'
  19. "allowSyntheticDefaultImports": true,
  20. // 严格校验,不能有没意义的anynull校验等选项
  21. "strict": true,
  22. "forceConsistentCasingInFileNames": true,
  23. "noFallthroughCasesInSwitch": true,
  24. // 配置的是我们代码的模块系统, Node.jsCommonJSES6标准的esnextrequirejsAMD
  25. "module": "esnext",
  26. "moduleResolution": "node", // 决定了我们编译器的工作方式,"node" and "classic"
  27. "resolveJsonModule": true,
  28. "isolatedModules": true, // 编译器会将每个文件作为单独的模块来使用
  29. "noEmit": true, // 表示当发生错误的时候,编译器不要生成 JavaScript 代码
  30. "jsx": "react" // 允许编译器支持编译react代码
  31. },
  32. "include": [
  33. "src"
  34. ],
  35. "exclude": [
  36. "node_modules",
  37. "**/*.spec.ts"
  38. ],
  39. "files": [
  40. "core.ts",
  41. "sys.ts",
  42. "types.ts",
  43. "scanner.ts",
  44. "parser.ts",
  45. "utilities.ts",
  46. "binder.ts",
  47. "checker.ts",
  48. "emitter.ts",
  49. "program.ts",
  50. "commandLineParser.ts",
  51. "tsc.ts",
  52. "diagnosticInformationMap.generated.ts"
  53. ],
  54. "extends": "./configs/base",
  55. }

jsx

  • preserve
  • react
  • react-jsx
  • react-jsxdev
  • react-native

tsconfig.json编译器配置文档