【问题标题】:Untyped function calls may not accept type arguments.ts(2347)无类型函数调用可能不接受类型 arguments.ts(2347)
【发布时间】:2022-01-12 14:00:28
【问题描述】:

我有一个带有打字稿的用户模式,下面是我的界面

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;

我收到 typescript 错误:无类型函数调用可能不接受用户模式上的类型参数,在 express 和 mongoose 中使用编辑器 Visual Studio。

【问题讨论】:

标签: typescript express mongoose types mongoose-schema


【解决方案1】:

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

const UserSchema = new Schema<IUser>(

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

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

这让我相信您导入 Schema 的方式有问题,或者安装 mongoose 的输入方式有问题。

我建议阅读mongoose - TypeScript Support

如果您无法弄清楚出了什么问题,那么告诉我们会有所帮助:

  • 如何导入Schema
  • 什么版本的猫鼬(可能@types/mongoose你正在使用)

【讨论】:

    猜你喜欢
    • 2018-12-30
    • 2018-03-02
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    相关资源
    最近更新 更多