文件名称:typegoose:Typegoose-使用TypeScript类定义Mongoose模型
文件大小:410KB
文件格式:ZIP
更新时间:2024-02-23 18:47:32
nodejs typescript mongodb js mongoose
鹅 (这些徽章来自typegoose:master) 使用TypeScript类定义Mongoose模型 基本用法 import { prop , getModelForClass } from '@typegoose/typegoose' ; import * as mongoose from 'mongoose' ; class User { @ prop ( ) public name ?: string ; @ prop ( { type : ( ) => [ String ] } ) public jobs ?: string [ ] ; } const UserModel = getModelForClass ( User ) ; // UserModel is a regular Mongoose Model with correct types ( async ( ) => { await mongoose . connect ( 'mongodb://localhost:27017/' , { useNewUrlParser : true ,