types / sequelize

The typings for https://github.com/sequelize/sequelize
63 stars 37 forks source link

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

Open billybarnum opened 6 years ago

billybarnum commented 6 years ago

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;
};
trusktr commented 4 years ago

I've opened a request to fix this in TypeScript. https://github.com/microsoft/TypeScript/issues/35822