Trying to implement a Mongoose model in Typescript. Scouring the Google has revealed only a hybrid approach (combining JS and TS). How would one go about implementing the
Here's how guys at Microsoft do it. here
import mongoose from "mongoose";
export type UserDocument = mongoose.Document & {
email: string;
password: string;
passwordResetToken: string;
passwordResetExpires: Date;
...
};
const userSchema = new mongoose.Schema({
email: { type: String, unique: true },
password: String,
passwordResetToken: String,
passwordResetExpires: Date,
...
}, { timestamps: true });
export const User = mongoose.model("User", userSchema);
I recommend to check this excellent starter project out when you add TypeScript to your Node project.
https://github.com/microsoft/TypeScript-Node-Starter