question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: Model.findAll returns any

See original GitHub issue
import { Sequelize, Model, DataTypes } from 'sequelize'

const sequelize = new Sequelize('postgres://user:password@localhost:5432/db')

export class User extends Model {
  public id?: number
  public name!: string
}

User.init(
  {
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
  },
  {
    sequelize,
    tableName: 'user',
  }
)

async function test() {
  const users = await User.findAll()
}

users is typed as any. I would have expected it to be of type User[]. I use sequelize 5.8.5 and typescript 3.4.5.

It seems that the static definition of findAll is overrided by a method.

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:6

github_iconTop GitHub Comments

6reactions
upcyoungcommented, Jul 31, 2019

see typescript install

@types/node (this is universally required) @types/validator @types/bluebird

After npm install @types/validator @types/bluebird, my question is resolved.

1reaction
Andrew1431commented, Jul 1, 2020

Oops sorry I thought your response was for another issue.

If you’re on <v6 of sequelize, you need to add bluebird types as a dependency. Otherwise upgrade sequelize to v6. That is what their current documentation represents regarding only needing validators and node types

Read more comments on GitHub >

github_iconTop Results From Across the Web

sequelize/sequelize-typescript - findAll with HasMany returns ...
I'm trying to make a one-to-many relationship using sequelize-typescript. But when I try to get the data, the relationship for many, returns ......
Read more >
TypeScript - Sequelize
Attributes<Model> and CreationAttributes<Model> will return the list of attributes of any model, no matter how they were created (be it Model.
Read more >
sequelize.Model.findAll JavaScript and Node.js code examples
Best JavaScript code snippets using sequelize.Model.findAll(Showing top 15 results out of 315) ; function selectApiByCondiction (condiction) { return Apis.
Read more >
Using Sequelize with TypeScript - LogRocket Blog
Sequelize ORM has some really cool model methods, including findAndCountAll , which returns a list of records and a count of all records ......
Read more >
How To Use Sequelize with Node.js and MySQL - DigitalOcean
Next, you will use Sequelize to create databases and models, ... the Sequelize findAll() method to return all book data from the database....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found