首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >非类型化函数调用可能不接受类型arguments.ts(2347)

非类型化函数调用可能不接受类型arguments.ts(2347)
EN

Stack Overflow用户
提问于 2021-12-07 13:36:33
回答 1查看 2.9K关注 0票数 2

我有一个带有类型记录的用户模式,下面是我的界面

代码语言:javascript
复制
interface IUser{
  name: string;
  email: string;
  password: string;
  isAdmin: boolean;
}

下面是用户模式

代码语言:javascript
复制
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编辑器的快递和蒙鹅。

EN

回答 1

Stack Overflow用户

发布于 2021-12-07 18:51:05

我假设您在这一行中得到了错误:

代码语言:javascript
复制
const UserSchema = new Schema<IUser>(

正如它所说的,Untyped function calls may not accept type arguments

  • 它所指的type argument是通用的<...>
  • 它所指的functionSchema,这意味着它不知道Schema是什么(输入为any)。

这使我相信,导入Schema的方式或安装mongoose类型的方式都有问题。

我建议阅读猫鼬- TypeScript支持

如果你不知道出了什么问题,那么如果你告诉我们:

  • 如何导入Schema
  • 什么版本的猫鼬(可能还在使用@types/mongoose )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70261102

复制
相关文章

相似问题

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