3
When using the Mongoose library, typing a model can be done with an interface that extends the type mongoose.Document
. This approach is working according to the example below:
import mongoose from 'mongoose';
export interface IModel extends mongoose.Document {
name: string;
}
const ModelSchema = new mongoose.Schema({
Name: { type: String },
});
export default mongoose.model<IModel>('model', ModelSchema);
In creating a function that is able to create a document based on that model, should send an object that has the typing exactly equal to the interface defined within the model, but without the extended properties of mongoose.Document
. The question is: Is there any way to delete or omit the extended properties of mongoose.Document
?
Below is an example of the function made to create a document:
import Model from 'models/Model';
export default async function createModelDocument(documentData: TIPO_SEM_AS_PROPRIEDADES_ESTENDIDAS): Promise<void> {
await Model.create(item);
}