types/sequelize

[v5] sequelize.import error TS4082: Default export of the module has or is using private name 'Bluebird'

billybarnum opened this issue · 1 comments

All the shops where I've worked that use sequelize use sequelize.import() to define models; it allows you to create more modular definition files.

I had a really hard time upgrading model definitions from v3 to v4 because of all the generics at the top level (and admittedly my typescript inexperience) but eventually I got it all working. Those generics are mostly gone in v5 which is great, but I'm having trouble again.

The code below returns error TS4082: Default export of the module has or is using private name 'Bluebird'

I note the v5 example on the home page uses init(), and poking around it almost seems from stackoverflow and other issues here that import() is being deprecated???

I'm not stuck on import() and will try out init(), but I'm thinking there's quite a bit of code out there that's gonna break if it goes, and it should be mentioned in the migration notes and the docs.

And if it still works but I just can't figger it out, can you help a guy out and tell me what I'm doing wrong below?

Thanks.

import {
    DataTypes,
    Sequelize,
} from 'sequelize';
 
export default (
    sequelize: Sequelize,
    dataTypes: typeof DataTypes
) => {
    const model = sequelize.define(
        'Profile',
        {
          id: {
            type: dataTypes.INTEGER,
            field: 'id',
            allowNull: false,
            primaryKey: true,
            references: {
                model: 'Customer',
                key: 'primaryKey'
            },
            onDelete: 'NO ACTION',
            onUpdate: 'NO ACTION'
        },
        screenName: {
            type: dataTypes.STRING(32),
            field: 'screenName',
            allowNull: true
        },
      },{
        tableName: 'Profile'
      });

      const Profile = class extends model {
        id: number;
        screenName?: string;
      }

      return Profile;
};

I've opened a request to fix this in TypeScript. microsoft/TypeScript#35822