首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nestjs -在@nestjs/microservices依赖项中声明mocha类型的问题

Nestjs -在@nestjs/microservices依赖项中声明mocha类型的问题
EN

Stack Overflow用户
提问于 2019-07-07 21:38:42
回答 4查看 1.1K关注 0票数 1

在我们的nestjs项目中嵌入@nestjs/terminus@6.1.0时,不承认@nestjs/microservices的类型:

$> tsc

代码语言:javascript
运行
复制
node_modules/@nestjs/microservices/external/redis.interface.d.ts:2:23 - error TS2688: Cannot find type definition file for 'mocha'.
2 /// <reference types="mocha" />
                        ~~~~~
Found 1 error.

当添加npm -save @types/mocha时,我显然会遇到与Jest的冲突,这是我们正在使用的测试框架.

$> tsc

代码语言:javascript
运行
复制
node_modules/@types/jest/index.d.ts:27:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'beforeEach' must be of type 'HookFunction', but here has type 'Lifecycle'.

27 declare var beforeEach: jest.Lifecycle;
...

现在,我找到的唯一解决办法是在tsconfig.json文件中使用tsconfig.json.不是很干净。

在这里,我的package.json文件的dep部分:

代码语言:javascript
运行
复制
[...]
"dependencies": {
    "@nestjs/common": "^6.0.5",
    "@nestjs/core": "^6.0.5",
    "@nestjs/mongoose": "^6.0.0",
    "@nestjs/graphql": "^6.2.1",
    "@nestjs/swagger": "^3.0.2",
    "@nestjs/terminus": "6.1.0",
    "@godaddy/terminus": "4.1.0",
    "app-root-path": "^2.2.1",
    "class-transformer": "^0.2.0",
    "class-validator": "^0.9.1",
    "codacy-coverage": "^3.1.0",
    "apollo-server-express": "^2.5.0",
    "graphql": "^14.3.0",
    "graphql-tools": "^4.0.4",
    "js-cache": "^1.0.3",
    "mongoose": "^5.4.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^6.4.0",
    "typescript": "^3.5.2",
    "winston": "^3.2.1"
  },
  "devDependencies": {
    "@nestjs/testing": "^5.0.0",
    "@types/express": "^4.0.39",
    "@types/jest": "^21.1.8",
    "@types/node": "^9.3.0",
    "@types/supertest": "^2.0.4",
    "jest": "^21.2.1",
    "nodemon": "^1.14.1",
    "prettier": "^1.11.1",
    "supertest": "^3.0.0",
    "ts-jest": "^21.2.4",
    "ts-loader": "^4.1.0",
    "ts-node": "^4.1.0",
    "tsconfig-paths": "^3.1.1",
    "tslint": "5.3.2"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "lib",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage"
  }

知道怎么干净地解决这个问题吗?

谢谢!

EN

回答 4

Stack Overflow用户

发布于 2019-07-09 08:43:00

对于那些有同样问题的人,我在下列条款中找到的一个替代下列条款的方法是:

  • 在我的项目overrides/mocha/index.d.ts中创建一个空文件
  • 添加到tsconfig文件"typeRoots":“重写”,“node_node/@types”

这将覆盖mocha def并避免def复制(因为我只使用Jest)。

它没有我想要的那么干净,但仍然比skipChekLib选项好。

票数 1
EN

Stack Overflow用户

发布于 2019-07-12 22:54:16

我们已经通过@nestjs/microservices@6.5.1的发布解决了这个问题--抱歉给您带来不便。https://github.com/nestjs/nest/issues/2534

票数 1
EN

Stack Overflow用户

发布于 2019-07-08 00:27:10

您可以通过将"types": []添加到compilerOptions并包括除@types/jest之外的所有类型包来使您的方法工作。在您的情况下,您可以使用"types": ["express", "node", "supertest"]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56926302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档