【问题标题】:Typescript error : Expected 0-1 arguments, but got 2打字稿错误:预期 0-1 个参数,但得到 2 个
【发布时间】:2021-03-13 16:50:27
【问题描述】:

我有使用时间戳的猫鼬模式。我尝试运行出错的代码

error TS2554: Expected 0-1 arguments, but got 2.

  { timestamps: true }

以下是代码架构

const Schema = mongoose.Schema;
const loginUserSchema = new Schema(
 {
    userId: { type: String, required: false }
 },
  { timestamps: true }
);

loginUserSchema.index({ userName: 'text' });

export const LoginUserModel = mongoose.model("loginUser", loginUserSchema) ;

我的 package.json

  "dependencies": {
    "@types/express": "^4.17.9",
    "@types/mongoose": "^5.7.7",
    "@types/node": "^13.9.2",
    "@types/react-router-dom": "^5.1.3",
    "body-parser": "^1.13.3",
    "config": "^3.3.2",
    "cors": "^2.8.1",
    "express": "^4.13.3",
    "express-session": "^1.14.2",
    "jsonwebtoken": "^8.5.1",
    "keycloak-connect": "github:keycloak/keycloak-nodejs-connect",
    "moment": "^2.29.1",
    "mongodb": "^3.5.5",
    "mongoose": "^5.10.9",
    "nodemon": "^2.0.5",
    "react-router-dom": "^5.1.2",
    "socket.io": "^2.3.0",
    "ts-node": "^8.10.2",
    "typescript": "^3.9.7"
  }

我需要做任何更改才能完成这项工作吗?

【问题讨论】:

    标签: typescript mongodb mongoose mongoose-schema


    【解决方案1】:

    这可能是@types/mongoose 中的错误 您应该可以使用:

    loginUserSchema.set('timestamps', true)
    

    绕过它。

    【讨论】:

      猜你喜欢
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 2021-07-29
      相关资源
      最近更新 更多