Definitelytyped: @types/sequelize is out of date

Created on 26 Apr 2019  路  10Comments  路  Source: DefinitelyTyped/DefinitelyTyped

If you know how to fix the issue, make a pull request instead.

  • [x] I tried using the @types/sequelize package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @.... @samuelneff @codeanimal @drinchev @drinchev @kukoo1 @oktapodia @morpheusxaut @TitaneBoy @zjy01 @nidzov @Raigen @todd @nrschultz @thomas-b @Antoine38660 @smff @truongkhanhduy95

If you do not mention the authors the issue will be ignored.

Issue:

It appears this is out of date. For example, the following code:

import * as Sequelize from "sequelize";

export interface IF_UserAttributes {
  name: string;
}
export interface IF_UserInstance extends Sequelize.Instance<IF_UserAttributes>, IF_UserAttributes {
}

produces the following error:

error TS2694: Namespace '".../node_modules/sequelize/types/index"' has no exported member
'Instance'

The same issue occurs if I try to use Sequelize.Models and Sequelize.DataTypes as well. Sequelize.Sequelize is the only one that works for me out of all the ones I've tried.

Here's my dependencies:

"devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/node": "^7.2.2",
    "@babel/preset-env": "^7.4.3",
    "@babel/register": "^7.4.0",
    "@types/bcrypt": "^3.0.0",
    "@types/bluebird": "^3.5.26",
    "@types/cors": "^2.8.5",
    "@types/dotenv": "^6.1.1",
    "@types/express": "^4.16.1",
    "@types/graphql": "^14.2.0",
    "@types/graphql-resolvers": "^0.2.0",
    "@types/ioredis": "^4.0.10",
    "@types/jsonwebtoken": "^8.3.2",
    "@types/node": "^11.13.7",
    "@types/nodemailer": "^4.6.7",
    "@types/pg": "^7.4.14",
    "@types/sequelize": "^4.27.48",
    "@types/validator": "^10.11.0",
    "nodemon": "^1.18.11",
    "typescript": "^3.4.5"
  },
  "dependencies": {
    "apollo-server": "^2.4.8",
    "apollo-server-express": "^2.4.8",
    "bcrypt": "^3.0.6",
    "cors": "^2.8.5",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "graphql": "^14.2.1",
    "graphql-redis-subscriptions": "^2.1.0",
    "graphql-resolvers": "^0.3.2",
    "ioredis": "^4.9.0",
    "jsonwebtoken": "^8.5.1",
    "nodemailer": "^6.1.0",
    "pg": "^7.9.0",
    "sequelize": "^5.5.0"
  }

Most helpful comment

Yeah it's working perfectly. It's so much simpler to use and easier to understand when you review your code.

All 10 comments

@TidyIQ It appears you're using the 5.x branch of Sequelize, which bundles its own types. The types installed via @types/sequelize are for 4.x. Indeed, it appears the error you listed above references the actual Sequelize package, not your explicitly installed types from this repository.

I would try removing @types/sequelize from your dependencies to see if that solves your issue. If not, I would open an issue with Sequelize directly.

Yep, you're right. I should have checked the version number in the @types/sequelize description. Thanks, problem solved.

I just:

  • Removed @types/sequelize
  • Deleted the node_modules folder
  • yarn install from scratch

I keep getting the error on the type:
image

Currently using v5.7.6

Sequelize.Instance no longer exists in v5

I've been trying to get Sequelize to work with Typescript by following their guides for the last 20 or so hours. I'm giving up. I just installed the sequelize-typescript npm package and will try to get it to work that way instead.

@TidyIQ Did sequelize-typescript work for you? I'm running into this same problem.

Yeah it's working perfectly. It's so much simpler to use and easier to understand when you review your code.

Great! I'll use that!

The simplest thing you could do is to remove sequelize v5 and run yarn add sequelize@4 && yarn add @types/sequelize@4.
The issue has been resolved for me with this solution.

Todd you are a genious you saved my life

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csharpner picture csharpner  路  3Comments

Loghorn picture Loghorn  路  3Comments

Zzzen picture Zzzen  路  3Comments

ArtemZag picture ArtemZag  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments