You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为应用内指定文件夹单独调整tsconfig的strict属性配置

配置方案

你可以通过 TypeScript 原生支持的overrides字段实现全局启用strict模式,仅针对指定文件夹关闭该规则,具体配置步骤如下:

  1. 把根目录tsconfig.json中的compilerOptions.strict改为true
  2. 在根目录tsconfig.json中新增overrides配置项,针对src/folder目录下的所有文件覆盖strict规则为false

修改后的完整tsconfig.json内容如下:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"],
  "overrides": [
    {
      "files": ["src/folder/**/*"],
      "compilerOptions": {
        "strict": false
      }
    }
  ]
}

备选方案(兼容3.5以下旧版本TypeScript)

如果你使用的TypeScript版本不支持overrides属性,可以通过多层tsconfig实现需求:

  1. 先修改根目录tsconfig,把strict设为true
  2. 在src/folder目录下新增一个tsconfig.json,内容如下:
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "strict": false
  }
}

内容的提问来源于stack exchange,提问作者Med El Mobarik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 20:57:00