#Methods inside a class are shown undefined but they are actually defined

11 messages · Page 1 of 1 (latest)

cinder glacier
#

Can anyone help me out? Trying this from a long time but no solution

#
  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

unique raft
#

Where is the class?

cinder glacier
#

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

unique raft
#

You need to put together an example. What is save and toSave?

cinder glacier
#

Can I send you the types? Because its from the mongoose library

unique raft
#

Make an example here

cinder glacier
#

Ok sir, let me try. But I am not sure how would I mock the types of that library?