typescript - 对象字面量只能指定已知的属性,而 'id' 不存在于类型 'ModelAttributes' 中
问题描述
我正在尝试使用 sequelize ORM 定义数据库用户模型,但我正在努力解决我需要帮助解决的 typescript 编译器引发的类型错误。我需要解决的代码。
export interface IUserAddModel{
email: string,
password: string
}
export interface IUserModel extends Sequelize.Model<IUserModel,IUserAddModel>{
id: number,
email: string
password: string
createdAt?: string
updatedAt?: string
}
export interface IUserViewModel{
id: number,
email: string
}
//Define a new model, representing a table in the DB.
export const User = sequelizeObj.define<IUserModel,IUserAddModel>('user', {
id:{ // This id property is bringing about the type issue.. yet I defined in the
//IUserModel interface. Do not know why it is bring compiler error issues
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey:true
},
email: Sequelize.STRING,
password: Sequelize.STRING
})
错误
Object literal may only specify known properties, and 'id' does not exist in type 'ModelAttributes<IUserModel, IUserAddModel>'
但是当我从定义的模型中删除 id 时,打字稿编译器停止抱怨,但我需要数据库表中的 id。
解决方案
推荐阅读
- azure - 将 Azure AD MFA 与 MIM 和本地应用程序结合使用
- php - 在选择下拉列表中显示月份及其编号 - laravel
- linux - Docker 卸载 Sawtooth 市场
- laravel - 为什么我的 Laravel 项目中的 VS Code 断点不起作用?
- javascript - 使用节点 js 错误 22 运行 python 脚本
- python - 是否有与 Matlab 函数 lhsnorm 等效的 python?
- hibernate - 从其他表 JPA 查询中仅获取用户相关记录
- hibernate - 存储空值的外键
- angular - Angular 5 RxJS 并重定向到仪表板页面而不首先加载主页
- php - [Route: get:manage_products] [URI: admin/manage-products/{id}] 缺少必需的参数?