#Methods inside a class are shown undefined but they are actually defined
11 messages · Page 1 of 1 (latest)
findOne(data: Partial<T>): Promise<T>;
createOne(data: Partial<T>): Promise<T>;
updateOne(id: string, data: Partial<T>): Promise<T>;
deleteOne(id: string): Promise<any>;
}
I have this interface
Where is the class?
Here you go
export class MongooseStrategy<T extends Document> implements CrudStrategy<T> {
async createOne(data: Partial<T>): Promise<T> {
// (1) Create a document from the provided data
const toSave = new this.model(data);
// (2) Save the document
const document = await toSave.save({ validateBeforeSave: true });
// (3) Return the document
return document;
}
}
There is the error I see here
Type 'Document<unknown, {}, T> & Document & { _id: ObjectId; }' is not assignable to type 'T'.
'Document<unknown, {}, T> & Document & { _id: ObjectId; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Document'
And the error coming from the return statement
You need to put together an example. What is save and toSave?
Can I send you the types? Because its from the mongoose library
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Make an example here
Ok sir, let me try. But I am not sure how would I mock the types of that library?