代码之家  ›  专栏  ›  技术社区  ›  Mahmoud

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

  •  1
  • Mahmoud  · 技术社区  · 3 年前

    我正在做一个VueJS项目。我们刚刚实现了Typescript (版本4.8.4) .

    我犯了这个错误 error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit' 在更新ts类型文件中的接口之后。

    在我的 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
      }
    }
    
    
    
    1 回复  |  直到 3 年前
        1
  •  1
  •   Mahmoud    3 年前

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

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

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

    推荐文章