In this article we will learn about some of the frequently asked TypeScript programming questions in technical like “typescript generic mongoose example” Code Answer. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on typescript was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Typescript. Below are some solution about “typescript generic mongoose example” Code Answer.
typescript generic mongoose example
xxxxxxxxxx
1
import { Schema, model, Document, Model } from 'mongoose';
2
3
declare interface IContact extends Document{
4
name: string;
5
email: string;
6
phone?: string;
7
message?: string;
8
course_enquiry?: string;
9
creation_date: Date;
10
}
11
12
export interface ContactModel extends Model<IContact> {};
13
14
export class Contact {
15
16
private _model: Model<IContact>;
17
18
constructor() {
19
const schema = new Schema({
20
name: { type: String, required: true },
21
email: { type: String, required: true },
22
phone: { type: String },
23
message: { type: String },
24
course_enquiry: { type: String },
25
creation_date: { type: Date, default: Date.now }
26
});
27
28
this._model = model<IContact>('User', schema);
29
}
30
31
public get model(): Model<IContact> {
32
return this._model
33
}
34
}Copied!