【发布时间】:2019-03-27 16:08:15
【问题描述】:
import mongoose, { Schema, model } from "mongoose";
var breakfastSchema = new Schema({
eggs: {
type: Number,
min: [6, "Too few eggs"],
max: 12
},
bacon: {
type: Number,
required: [true, "Why no bacon?"]
},
drink: {
type: String,
enum: ["Coffee", "Tea"],
required: function() {
return this.bacon > 3;
}
}
});
我在运行此代码时遇到的两个错误是:
- 类型 '{ type: StringConstructor; 上不存在属性 'bacon' 枚举:字符串[];必需:() => 任何; }'
- “required”隐含返回类型“any”,因为它没有返回类型注释,并且在其返回表达式之一中直接或间接引用。
【问题讨论】:
标签: javascript mongodb typescript mongoose