打字稿错误:预期 0-1 个参数,但得到 2 个
Posted
技术标签:
【中文标题】打字稿错误:预期 0-1 个参数,但得到 2 个【英文标题】:Typescript error : Expected 0-1 arguments, but got 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"
我需要做任何更改才能完成这项工作吗?
【问题讨论】:
【参考方案1】:这可能是@types/mongoose
中的错误
您应该可以使用:
loginUserSchema.set('timestamps', true)
绕过它。
【讨论】:
以上是关于打字稿错误:预期 0-1 个参数,但得到 2 个的主要内容,如果未能解决你的问题,请参考以下文章