我有一个带有类型记录的用户模式,下面是我的界面
interface IUser{
name: string;
email: string;
password: string;
isAdmin: boolean;
}
下面是用户模式
const UserSchema = new Schema<IUser>(
{
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
validate: [validator.isEmail, "Please provide a valid email"],
},
password: {
type: String,
required: true,
minlength: 8,
},
isAdmin: {
type: Boolean,
required: true,
default: false,
},
},
{
timestamps: true,
}
);
const UserModel = model("User", UserSchema);
module.exports = UserModel;
我得到了类型记录错误:非类型化函数调用可能不接受用户模式上的类型参数,在使用visual编辑器的快递和蒙鹅。
发布于 2021-12-07 18:51:05
我假设您在这一行中得到了错误:
const UserSchema = new Schema<IUser>(
正如它所说的,Untyped function calls may not accept type arguments
。
type argument
是通用的<...>
。function
是Schema
,这意味着它不知道Schema
是什么(输入为any
)。这使我相信,导入Schema
的方式或安装mongoose
类型的方式都有问题。
我建议阅读猫鼬- TypeScript支持。
如果你不知道出了什么问题,那么如果你告诉我们:
Schema
@types/mongoose
)https://stackoverflow.com/questions/70261102
复制相似问题