79459441

Date: 2025-02-22 10:35:21
Score: 1
Natty:
Report link

Here is my simple answer for anyone looking to achieve this :

Basically, you'll want to add your properties and give a name to it.

Then you will create a new definition that includes the model and your properties.

You will finally call it and enjoy !

// Schema.model.js

import mongoose from 'mongoose'

/**
 * Schema Model w/ methods
 * @typedef {typeof mongoose.Model & sampleSchema} Schema
 */

/**
 * @typedef {Object} sampleSchema
 * @property {string} data 
 */
const sampleSchema = mongoose.Schema({
    data: { type: String },
})

export default mongoose.model('Schema', sampleSchema);

Now, when you will @type your variable it will include the model & your properties

// Schema.controller.js
import Schema from '../models/Schema.model.js';


function getMySchema() {
  /** @type {import('../models/Schema.model.js').Schema} */
  const myAwsomeSchema = new Schema({})
  
  // When you will use your variable, it will be able to display all you need.

}

Enjoy !

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @type
  • Low reputation (1):
Posted by: Adrien Quijo