这是一个 TypeScript 项目配置文件 tsconfig.json 的示例,用于指导如何设置 TypeScript 项目的基本配置。

  • 编译选项:指定 TypeScript 编译器选项,如输出文件格式、模块解析策略等。
  • 包含文件:指定需要编译的文件或目录。
  • 排除文件:指定需要排除的文件或目录。

示例配置

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

解释

  • target: 设置编译后的 JavaScript 代码的目标环境(如 es5, es6 等)。
  • module: 设置生成的模块代码的类型(如 commonjs, es6 等)。
  • strict: 启用所有严格类型检查选项。
  • esModuleInterop: 允许默认导入非 ES 模块。
  • skipLibCheck: 跳过所有声明文件(.d.ts)的类型检查。
  • forceConsistentCasingInFileNames: 强制文件名大小写一致性。

扩展阅读

更多关于 TypeScript 的配置选项和最佳实践,请参考TypeScript 官方文档


(center) TypeScript 配置示例