Fixing lint warning: void function return type is used — mongoDB

I am getting a Typescript lnt warning

using @types/mongdodb

export const Searchable = <TSchema extends { _id?: ObjectId }>() => {

  // TypeScript generic to ensure this uses the correct overload of Mongo.findOne
  static findOne<T extends TSchema>(
    filter: TSchemaFilter,
    options?: FindOneOptions<T extends TSchema ? TSchema : T>
  ) {
    return this.collection.findOne(filter, options);
  }

  ...

}

// reports void function return value is used
const document = await MyDocument.findOne({ myFilter});

I can suppress this by doing:

  // TypeScript generic to ensure this uses the correct overload of Mongo.findOne
  static findOne<T extends TSchema>(
    filter: TSchemaFilter,
    options?: FindOneOptions<T extends TSchema ? TSchema : T>
  ) : any {
    return this.collection.findOne(filter, options);
  }

Is there a better way?



Read more here: https://stackoverflow.com/questions/67935627/fixing-lint-warning-void-function-return-type-is-used-mongodb

Content Attribution

This content was originally published by vogomatix at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: