Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

mongodb - Mongoose 5.11.11 SchemaDefinition Typing

Mongoose recently updated to accept a model generic it works well with a string type but not with a boolean type. Type 'boolean' is not assignable to type 'SchemaDefinitionProperty<undefined>'.

interface User {
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  isVerified?: boolean;
}

const UserSchemaDefinition: SchemaDefinition<User> = {
  firstName: {
    type: String,
    trim: true,
    required: true,
  },
  lastName: {
    type: String,
    trim: true,
    required: true,
  },
  email: {
    type: String,
    required: true,
  },
  password: {
    type: String,
    required: true,
    private: true,
  },
  isVerified: {
    type: Boolean,
    default: false,
  },
};

const UserSchema = new mongoose.Schema(UserSchemaDefinition); // Typescript complains here.

Example is posted here https://github.com/Automattic/mongoose/pull/9761


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...