Как правильно создать таблицу sequelize, используя при этом ts?
Мой попытка создания, но получаю ошибку при попытке использовать User.create(...)
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
}
Сокращенный пример из документации выдает такую же ошибку:
import { Model, DataTypes } from 'sequelize';
import { sequelize } from '../';
class User extends Model {
public id!: number; // Note that the `null assertion` `!` is required in strict mode.
public email!: string;
public password!: string; // for nullable fields
public nickname!: string;
// timestamps!
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
User.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true,
},
nickname: {
type: new DataTypes.STRING(128),
allowNull: false,
},
email: {
type: new DataTypes.STRING(128),
allowNull: false
}
},
{
tableName: 'users',
sequelize
}
);
export { User }