带有Sequelize.Model的VsCode intelliSense问题

时间:2019-07-24 11:56:57

标签: javascript node.js sequelize.js

我的智能感知类Sequelize.Model有一些问题 设置属性Sequelize.Model后,Model中的许多方法都没有与vscode中的IS关联。

With default class

With @property jsdoc Sequelize.Model


 /**
  * @typedef DB
  * 
  * @property {Sequelize} sequelize
  * @property {Sequelize.Model} User
  * @property {Sequelize.Model} Product
  */

/**
 * @type {DB}
 */
const db = {
    ...models,
    sequelize
};
db.User.

1 个答案:

答案 0 :(得分:0)

您还必须导入typedef

对我来说,这很好!

'use strict';
/**
* @typedef {import('sequelize').Sequelize} Sequelize
* @typedef {import('sequelize/types')} DataTypes
*/

/**
* @param {DataTypes} DataTypes
* @param {Sequelize} Sequelize
* @returns
*/
module.exports = (Sequelize, DataTypes) => {



    const Post = Sequelize.define('Post', {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.INTEGER
        },
        headline: {
            type: DataTypes.TEXT
        },
        body: {
            type: DataTypes.TEXT
        },
        createdAt: {
            type: DataTypes.DATE,

            defaultValue: Sequelize.literal('NOW()')
        },
        updatedAt: {
            type: DataTypes.DATE,

            defaultValue: Sequelize.literal('NOW()')
        },
    }, { timestamps: true });
    Post.associate = function (models) {
        // associations can be defined here
        Post.belongsTo(models.User);
    };
    return Post;
};