javascript - WebStorm Node.Js Sequelize Model type hint -
i'd know how type-hint node.js sequelize models in webstorm better code completion.
at least able figure out, how code completion model properties. i'm missing model functions sequelize.
this how far 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 automatically fills db models files // resulting in { examplemodel : examplemodel, anothermodel: anothermodel} module.exports = db;
now i'm able type like
var models = require(__base + 'models'); models.ex // webstorm suggets "examplemodel" models.examplemodel. // webstorm suggets "id", "someproperty", "classmethods" (the last 1 weird, doesn't matter)
and code completion models , properties. i'm missing sequelize methods "upsert", "create", ...
does know how code completion also?
i add fake method improve ide autocomplete
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 ide autocomplete'); }
Comments
Post a Comment