【发布时间】:2020-05-29 05:56:37
【问题描述】:
我正在尝试创建一个动态架构,其中需要基于另一个字段的值的字段。
示例架构:
const foo = new Schema({
status: {
type: String,
default: "in_process"
},
route: {
type: String,
default: ""
},
code: {
type: Number,
default: 0,
required: function () {
return this.route === "Results";
}
},
});
当我这样做时,TS 会通知我这个错误:
Property 'route' does not exist on type 'Schema<any> | SchemaTypeOpts<any> | SchemaType'.
Property 'route' does not exist on type 'Schema<any>'.
我应该如何正确处理这种情况?
【问题讨论】:
标签: typescript mongoose mongoose-schema