Hey @vince !
Using the example from the Woodshop, here’s the static interface:
import { Model } from "sequelize";
export default class Users extends Model {
public id!: number;
public firstname!: string;
public lastname!: string;
public readonly createdAt: Date;
public readonly updatedAt: Date;
}
And here’s the runtime schema that is actually used:
import Users from '../interfaces/users';
export default (sequelize, DataTypes) => {
Users.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
firstname: {
type: new DataTypes.STRING(128),
allowNull: false
},
lastname: {
type: new DataTypes.STRING(128),
allowNull: false
}
},{
tableName: "users",
modelName: 'users',
sequelize,
}
);
return Users;
}
I’ve had to define twice every property and every type.
I’m unsure if the type
field of every model is safely typed of if I can define one of the interface property as number
and the runtime property as new DataTypes.STRING(128)
.
Using a project such as the one linked in OP would allow to bypass this duality (example from their README):
@Table
class Person extends Model {
@Column
name: string;
@Column
birthday: Date;
@HasMany(() => Hobby)
hobbies: Hobby[];
}
PS: Thanks for the welcome =)