1

I want to be able to have JSDoc understand Mongoose Schemas so I can use the types in @param, @returns, and @type. I managed to achieve that using this question. This works great:

/**
 * @class TheModel
 */
const theSchema = new Schema({
    . . .
});

The problem is, we left the _id off the schemas because they're implicit, but this means JSDoc doesn't know about them, and gives warnings if you try to access _id on a document.

How can I tell JSDoc about the extra _id field that it should include, despite it not being on the schema?

I tried creating a @mixin MongooseModel with @property for _id, and then changing my docs to:

/**
 * @class TheModel
 * @mixes MongooseModel
 */
const theSchema = new Schema({
    . . .
});

And along a similar vein, I tried creating a @interface with an _id field, and then adding @implements to the schema docs. Neither works. Webstorm does not give suggestions for _id.

I would prefer not to add a _id field to the schema since that requires the _id to be included when creating documents.


WebStorm 2023.1.2

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117

0 Answers0