WebStorm Node.JS Sequelize Tooltip Type Type

I would like to know how to type node.js fonts in WebStorm models for better code completion.

At least I was able to figure out how to get code completion for model properties. But I do not have model functions from sequelize.

Here is how far I got:

models / exampleModel.js

/**
 * @module ExampleModel
 * @typedef {Object}
 * @property {ExampleModel} ExampleModel
 */


 /**
 *
 * @param sequelize {sequelize}
 * @param DataTypes {DataTypes}
 * @returns {Model}
 */
module.exports = function (sequelize, DataTypes) {
    var ExampleModel = sequelize.define('ExampleModel', {
       id: {
          type: DataTypes.BIGINT.UNSIGNED,
          primaryKey: true
       },

       someProperty: {
          type: DataTypes.BOOLEAN,
          defaultValue: true
       }
    }, {
        classMethods: {
            associate: function (models) {
               ExampleModel.belongsTo(models.AnotherModel, {foreignKey: 'id'});
            }
        }
    });
    return ExampleModel;
};

models / index.js

'use strict';

/**
 * @module models
 * @typedef {Object} models
 * @property {ExampleModel} ExampleModel
 * @property {AnotherModel} AnotherModel
 */

var db        = {};

// code that automatically fills db with models from files
// resulting in something like { ExampleModel : ExampleModel, AnotherModel: AnotherModel}

module.exports = db;

Now I can type something like

var models = require(__base + 'models');
models.Ex // Webstorm suggets "ExampleModel"
models.ExampleModel. // WebStorm suggets "id", "someProperty", "classMethods" (the last one is weird, but doesn't matter)

and get code completion for models and their properties. Now I miss the continuation methods like "upsert", "create", ...

Does anyone know how to get code completion for the same?

+5
source share
2 answers

IDE

db.sequelize = sequelize;
db.Sequelize = Sequelize;

// eslint-disable-next-line
function enableAutocomplete() {

  /**  @type {Model|Address|*} */
  db.Address = require('./address')();

  /**  @type {Model|Group|*} */
  db.Group = require('./group')();

  throw new Error('this function for IDE autocomplete');
}
+1

WebStorm 2019 Sequelize:

require('sequelize');

. , " TypeScript "

WebStorm, express.js.https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html

0

Source: https://habr.com/ru/post/1611095/


All Articles