Typescript: Model.findAll returns any
See original GitHub issueimport { 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
see typescript install
@types/node (this is universally required) @types/validator @types/bluebird
After
npm install @types/validator @types/bluebird
, my question is resolved.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