我将我的应用程序从使用tsd升级为带打字稿的打字,除了猫鼬模型外,一切正常。我无法确定如何配置新的更改,我尝试了几种方法,但是它们不起作用。我通过使用mongoose.Model扩展它而丢失了模型上设置的保存和其他方法。以下是我在破坏性变化之前进行设置的方法
import mongoose = require('mongoose');
import {NextFunction} from 'express';
let Schema = mongoose.Schema;
interface IUser extends mongoose.Document {
username: string;
password: string;
authenticate(password: string): boolean;
findUniqueUsername(username: string, suffix: number, next: NextFunction): void;
}
interface IUserModel extends mongoose.Model<IUser> {
hashPassword(password: string): string;
}
var UserSchema: mongoose.Schema = new Schema({
username: {
type: String,
required: 'Please fill in the user name',
unique: true
},
password: {
type: String
}
});
UserSchema.methods.hashPassword = function (password) {...};
UserSchema.methods.authenticate = function (password) {...};
UserSchema.statics.findUniqueUsername = function (username, suffix, next) {...};
var User = <IUserModel> mongoose.model('User', UserSchema);
export {IUser, IUserModel, User}
我也遇到了错误:&#34;界面只能扩展一个类或另一个类&#34;对于IUserModel,扩展了mongoose.Modelinterface。这一切都很有效,直到我改为打字。什么是新的做法。