typegoose使用报错

柯基
  • 39

koa项目引入typegoose后运行报错:
image.png

具体报错内容:

6:54:09 PM - File change detected. Starting incremental compilation...

node_modules/@typegoose/typegoose/lib/hooks.d.ts(8,41): error TS2707: Generic type 'Query<ResultType, DocType, THelpers, RawDocType>' requires between 2 and 4 type arguments.

6:54:09 PM - Found 1 error. Watching for file changes.

泛型类型“Query<ResultType, DocType, THelpers, RawDocType>”需要介于 2 和 4 类型参数之间。

model.js:

import { getModelForClass, prop } from '@typegoose/typegoose'

class StoryClass {
  @prop()
  public id?: string;

  @prop()
  public name?: string;
}

const StoryModel = getModelForClass(StoryClass)

export default StoryModel

依赖版本:

"dependencies": {
    "@typegoose/typegoose": "^7.6.1",
    "axios": "^0.21.1",
    "dayjs": "^1.10.5",
    "koa": "^2.13.1",
    "koa-router": "^10.0.0",
    "mongoose": "^5.13.1"
  },
  "devDependencies": {
    "@types/koa": "^2.13.1",
    "@types/koa-router": "^7.4.1",
    "@types/mongoose": "^5.11.97",
    "@types/node": "^14.14.37",
    "ts-node": "^9.1.1",
    "tsc-watch": "^4.4.0",
    "typescript": "^4.2.4"
  },

有大佬帮忙看看什么问题吗?

回复
阅读 682
1 个回答
沉默
  • 3
新手上路,请多包涵

应该是你安装的@types/mongoose和mongoose自带的.d.ts文件有冲突,mongoose在5.10.18开始自带.d.ts文件了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏