相关疑难解决方法(0)

Mongoose的Typescript方式......?

试图在Typescript中实现Mongoose模型.搜索谷歌只揭示了混合方法(结合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 …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose node.js typescript

56
推荐指数
11
解决办法
4万
查看次数

标签 统计

javascript ×1

mongoose ×1

node.js ×1

typescript ×1