我的智能感知类Sequelize.Model有一些问题 设置属性Sequelize.Model后,Model中的许多方法都没有与vscode中的IS关联。
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.
答案 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;
};