typescript 选项“emitDeclarationOnly”不能与选项“noEmit”一起指定

8yoxcaq7  于 2023-06-07  发布在  TypeScript
关注(0)|答案(1)|浏览(746)

我正在做一个VueJS项目。我们刚刚实现了Typescript (版本4.8.4)
在更新ts类型文件中的接口后,我得到了这个错误error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'
在我的tsconfig文件中,我们只声明了"emitDeclarationOnly": true,,但似乎noEmit是在node_modules下与其他包一起声明的。
下面是tsconfig文件的完整内容

{
  "compilerOptions": {
    "target": "es6",
    "module": "es6",
    "strict": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true,
    "isolatedModules": true,
    "emitDeclarationOnly": true,
    "outDir": "tsdist",
    "types": [
      "webpack-env",
      "jest"
    ],
    "typeRoots": [
      "./node_modules/@types",
    ],
    "paths": {
      "@/*": [
        "src/*"
      ],
      "AppCheckout/*": ["src/assets/scripts/AppComponent/Checkout/src/*"],
      "AppCommon/*": ["src/assets/scripts/AppComponent/Common/src/*"],
      "AppPublication/*": ["src/assets/scripts/AppComponent/Publication/src/*"],
      "AppStore/*": ["src/assets/scripts/AppComponent/Store/src/*"]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
, "src/assets/scripts/globals/Container/Core/initContainer.js"  ],
  "exclude": [
    "node_modules",
    "./tasks"
  ],
  "vueCompilerOptions": {
    "target": 2.7
  }
}
lrpiutwd

lrpiutwd1#

我找到了这个问题的根源。顺便说一下,我们在项目上使用lint-staged包来验证提交前的修改。在这个包的配置文件中,我们通过强制使用noEmit选项来检查typescript文件,而在tsconfig配置文件中,我们定义了emitDeclarationOnly

"src/**/*.ts": [
    "tsc-files --noEmit"
  ],

因此,有必要协调这两种配置,以避免这种错误。

相关问题