Skip to content

v2.0.0: compiler error when using stricter typing Model attributes signature #882

Closed
@spinlud

Description

@spinlud

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();
})();

image

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions