猫鼬打字的方式...?
2022-08-30 05:04:43
尝试在Typescript中实现猫鼬模型。搜索Google只发现了一种混合方法(结合JS和TS)。如果没有JS,如何以我相当幼稚的方法实现User类?
希望能够在没有行李的情况下使用IUserModel。
import {IUser} from './user.ts';
import {Document, Schema, Model} from 'mongoose';
// mixing in a couple of interfaces
interface IUserDocument extends IUser, Document {}
// mongoose, why oh why '[String]'
// TODO: investigate out why mongoose needs its own data types
let userSchema: Schema = new Schema({
userName : String,
password : String,
firstName : String,
lastName : String,
email : String,
activated : Boolean,
roles : [String]
});
// interface we want to code to?
export interface IUserModel extends Model<IUserDocument> {/* any custom methods here */}
// stumped here
export class User {
constructor() {}
}