mongoose-to-typescript
It just create typescript classes from mongoose model or schema.\
It works with (MongooseType : TypescriptType):
- Number : number
- String : string
- Boolean : boolean
- Date : Date
- Array : Array
- ObjectID (not id) : Referenced model class
- ObjectID (id) : string
Installation
```bash $ npm install -g mongoose-to-typescript ```Usage
Model naming convention
The model files must be as follow classNameModel.js (for example AuthorizedWeightCategoryModel.js)CLI
Generates a typescript class from a mongoose model file: ```bash $ sudo mongoose-to-typescript -p ./models/ -m -o ./output Created AuthorizedWeightCategory.ts Created AutoSinister.ts Created BusinessProvider.ts Created Customer.ts Created Enterprise.ts Created PaymentFrequency.ts Created Person.ts Created Policy.ts Created Position.ts ```Options
-V, --version
- output the version number\
-p, --path <inputPath>
- Input directory where your schema or model are\
-m, --model
- to translate mongoose model to typescript\
-s, --schema
- to translate mongoose schema (not model, light difference) to typescript\
-o, --output <output>
- Output directory\
`-h, --help` - output usage information
Available types
- string - number - date - boolean - array - objectIdRendering
output/Vehicle.ts : ```typescript import VehicleBrand from './VehicleBrand'; import VehicleModel from './VehicleModel'; import Customer from './Customer'; class Vehicle {public brand : VehicleBrand = VehicleBrand();
public model : VehicleModel = VehicleModel();
public immatriculation : string = "";
public owner : Customer = Customer();
public _id : string = "";
}
```