我正在做一个VueJS项目.我们刚刚实现了TypeScrip (version 4.8.4).

在更新ts类型文件中的接口后,我收到此错误error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.

在我的tsconfig文件中,我们只声明了"emitDeclarationOnly": true,,但看起来noEmit与nodeMODULES下的其他包一起声明了.

以下是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
  }
}


推荐答案

我找到了这个问题的根源. 顺便说一句,我们在提交之前使用项目上的lint-staged包来验证修改. 在这个包的配置文件上,我们通过强制使用noEmit选项来判断类型脚本文件,而在tsconfig配置文件上我们定义了emitDeclarationOnly

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

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

Typescript相关问答推荐

如何正确修复TypScript 4.7到4.8升级中的TS 2345编译错误

我用相同的Redux—Toolkit查询同时呈现两个不同的组件,但使用不同的参数

rxjs forkJoin在错误后不会停止后续请求

学习Angular :无法读取未定义的属性(正在读取推送)

如何在TypeScrip中正确键入元素和事件目标?

在分配给类型的只读变量中维护const的类型

React Typescript项目问题有Redux-Toolkit userSlice角色问题

对于始终仅在不是对象属性时才抛出的函数,返回Never

TypeScrip中的类型安全包装类

如何将spread operator与typescripts实用程序类型`参数`一起使用

17个Angular 的延迟观察.如何在模板中转义@符号?

如何键入并类型的函数&S各属性

KeyOf关键字在特定示例中是如何工作的

如何在具有嵌套数组的接口中允许新属性

为什么类型脚本使用接口来声明函数?他的目的是什么.

如何创建一个将嵌套类属性的点表示法生成为字符串文字的类型?

类型脚本中函数重载中的类型推断问题

Typescript泛型调用对象';s方法

在类型{}上找不到带有string类型参数的索引签名 - TypeScript

如何在由函数参数推断的记录类型中具有多个对象字段类型