isDeleted()
isDeleted
领域
我有这样的想法:
export class Factory<E> {
private readonly _model: Model<Document & E>;
public get model(): Model<Document & E> {
return this._model;
}
constructor(config: IFactoryConfiguration) {
// ...
let schema: Schema = new Schema(this.definition);
this._model = this.connection.model<Document & E>(this.name, schema);
}
}
那么我有:
export class UserFactory extends Factory<IUser> {
constructor(connection: Connection) {
super({
connection: connection,
name: 'User',
definition: UserSchema
});
}
}
以及:
export const UserSchema: SchemaDefinition = {
// ...
isDeleted: {
type: Boolean,
default: false
} // ...
}
IUser
有
isDeleted: boolean;
财产等。
现在,我想在每次启动服务器时创建/更新系统用户:
let system = await this.factories.user.model.findOne({
'isSystem': true
});
if (!system) {
system = new this.factories.user.model();
system.isSystem = true;
system.isDeleted = true; <-- error here
await system.save();
}
问题是我有
属性(在本例中为
尤瑟
),但猫鼬有
isDeleted()
方法在它的
Document
Intersection Type
属于
Document & IUser
,这里有干扰。我得到的错误是:
错误:(239,7)TS2322:类型“true”不能分配给类型“({(isDeleted:boolean):void;():boolean;}&false);({(isDeleted:boolean):void;():boolean;}&true)”。
因为有
isDeleted(): boolean;
方法(看一看
here
).我如何解决这个问题?
"mongoose": "^4.13.17",
"@types/mongoose": "^4.7.23",
到
"mongoose": "^5.4.7",
"@types/mongoose": "^5.3.10",
我正在使用
"typescript": "^3.2.2",