sequelize / sequelize-typescript

Decorators and some other features for sequelize
MIT License
2.79k stars 282 forks source link

Namespace collision for sequelize.QueryOptions? #342

Closed smasilamani-cfins closed 6 years ago

smasilamani-cfins commented 6 years ago

Hello

I am getting the below error

Argument of type 'sequelize.QueryOptions' is not assignable to parameter of type 'sequelize.QueryOptions'.
  Types of property 'instance' are incompatible.
    Type 'sequelize.Instance<any>' is not assignable to type 'sequelize.Instance<any>'. Two different types with this name exist, but they are unrelated.
      Types of property 'Model' are incompatible.
        Type 'sequelize.Model<sequelize.Instance<any>, any>' is not assignable to type 'sequelize.Model<sequelize.Instance<any>, any>'. Two different types with this name exist, but they are unrelated.
          Types of property 'Instance' are incompatible.
            Type '() => sequelize.Instance<any>' is not assignable to type '() => sequelize.Instance<any>'. Two different types with this name exist, but they are unrelated.
              Type 'sequelize.Instance<any>' is not assignable to type 'sequelize.Instance<any>'. Two different types with this name exist, but they are unrelated.

Following is part of my code

import { Sequelize } from 'sequelize-typescript';

import * as sequelize from 'sequelize';

this.sequelize = new Sequelize({
                database: IQConfig.db.database,
                username: IQConfig.db.user,
                password: IQConfig.db.password,
                host: IQConfig.db.server,
                dialect: 'mssql',
                operatorsAliases: false,
                pool: {
                    max: IQConfig.db.pool.max,
                    min: IQConfig.db.pool.min,
                    acquire: 30000,
                    idle: 10000
                },
                modelPaths: [__base + '/**/*Sqlz.*'],
                logging: console.log
                // logging: false
            });

In a different method :

const queryOption: sequelize.QueryOptions = <sequelize.QueryOptions>{
            type: Sequelize.QueryTypes.SELECT
        };
        const resp: any = await this.sequelize.query(`SELECT NEXT VALUE FOR ${sequenceName} AS id`,
            queryOption);
        return resp[0] ? resp[0].id : null;

I get this error on the query method second parameter.

Versions :

@types/sequelize : 4.27.12 sequelize-typescript : 0.6.3 sequelize : 4.37.5

I do not get any error if I set my version of @types/sequelize to 4.27.5 . Thanks

RobinBuschmann commented 6 years ago

Hi @saachinsiva, did you install the sequelize typings additionally?

smasilamani-cfins commented 6 years ago

@RobinBuschmann

I did not install anything additionally other than updating my package.json file.

"dependencies": {
    "aigle": "^1.11.0",
    "array-query": "^0.1.2",
    "aws-sdk": "^2.216.1",
    "body-parser": "^1.18.2",
    "cache-manager": "^2.5.0",
    "cache-manager-ioredis": "^1.0.1",
    "connect-timeout": "^1.9.0",
    "express": "^4.16.2",
    "helmet": "^3.9.0",
    "json2csv": "^3.11.5",
    "json2typescript": "^1.0.5",
    "jsonwebtoken": "^8.1.0",
    "lodash": "^4.17.4",
    "moment": "^2.19.1",
    "moment-timezone": "^0.5.13",
    "multer": "^1.3.0",
    "nodemailer": "^4.1.3",
    "redis": "^2.8.0",
    "reflect-metadata": "^0.1.12",
    "request": "^2.83.0",
    "rimraf": "^2.6.2",
    "sequelize": "^4.33.4",
    "sequelize-typescript": "^0.6.2",
    "tedious": "^2.3.1",
    "tracer": "^0.8.11",
    "web-request": "^1.0.7",
    "xml2js": "^0.4.19"
  },
  "devDependencies": {
    "@types/aws-sdk": "^2.7.0",
    "@types/body-parser": "^1.16.8",
    "@types/connect-timeout": "0.0.33",
    "@types/express": "^4.11.1",
    "@types/helmet": "0.0.37",
    "@types/jsonwebtoken": "^7.2.5",
    "@types/lodash": "^4.14.100",
    "@types/moment": "^2.13.0",
    "@types/moment-timezone": "^0.5.3",
    "@types/multer": "^1.3.6",
    "@types/node": "^9.4.0",
    "@types/nodemailer": "^4.3.2",
    "@types/redis": "^2.8.5",
    "@types/request": "^2.47.0",
    "@types/rimraf": "^2.0.2",
    "@types/sequelize": "^4.27.5",
    "@types/soap": "^0.21.0",
    "@types/xml2js": "^0.4.2",
    "codelyzer": "^4.1.0",
    "nodemon": "^1.14.11",
    "ts-node": "^5.0.0",
    "tslint": "^5.9.1",
    "typescript": "^2.7.2"
  }
RobinBuschmann commented 6 years ago

sequelize-typescript already installs the sequelize typings and your additional redundant dependency to "@types/sequelize": "^4.27.5", can probably lead to issues. Please remove this dependency and give it another try :). Hopefully this helps

smasilamani-cfins commented 6 years ago

@RobinBuschmann

Thanks for helping me out. As I said earlier in my comment if I hard set the version of sequelize to 4.27.5 everything works fine. I was trying to update the sequelize types to the latest version and it started breaking. But anyway it is not critical for us to upgrade right not and we are all set with using version 4.27.5

Thanks again.