Closed
Description
It seems there are still problems when defining models with stricter typing syntax on attributes, as already reported here #844.
The following code does not compile:
import { Optional } from 'sequelize';
import { Sequelize, Model } from "sequelize-typescript";
interface PersonAttributes {
id: number;
name: string;
country?: string;
}
interface PersonCreationAttributes extends Optional<PersonAttributes, 'country'> {}
class Person extends Model<PersonAttributes, PersonCreationAttributes> implements PersonAttributes {
id!: number;
name!: string;
country?: string;
}
(async () => {
const sequelize = new Sequelize({
dialect: 'mysql',
host: 'localhost',
port: 3306,
database: 'testdb',
username: 'admin',
password: 'admin',
logQueryParameters: true,
logging: true,
});
await sequelize.authenticate();
await sequelize.addModels([Person]); // <-- compiler complains
await sequelize.close();
})();
See also: