我正在尝试这样做:
interface UserI {
id?: number | null,
name: string,
password: string
}
@Table(
{
tableName: 'user',
timestamps: true
}
)
class User extends Model implements UserI{
@AutoIncrement
@PrimaryKey
@Column(INTEGER)
id!: number
@AllowNull(false)
@NotEmpty
@Column(STRING)
name!: string
@AllowNull(false)
@NotEmpty
@Column(STRING)
password!: string
}
但不断报错:TypeError: Class constructor Model cannot be invoked without 'new';
我究竟做错了什么?
最佳答案
import { Model, Column, Table, AutoIncrement, PrimaryKey, NotEmpty, AllowNull } from "sequelize-typescript";
@Table(
{
tableName: 'user',
timestamps: true
}
)
export class User extends Model<User>{
@AutoIncrement
@PrimaryKey
@Column
id!: number
@AllowNull(false)
@NotEmpty
@Column
name!: string
@AllowNull(false)
@NotEmpty
@Column
password!: string
}
不需要接口(interface)。
关于typescript - 如何使用 typescript 正确创建表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62111327/