Definitelytyped: [@types/sequelize] `findById` is deprecated, `findByPk` is unavailable

Created on 26 Oct 2018  路  3Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [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
  • [ ] 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 @babolivier @kukoo1 @oktapodia @morpheusxaut @TitaneBoy @zjy01 @nidzov @Raigen @todd @nrschultz @thomas-b

According to the API reference, Model.findById no longer exists and Model.findByPk is the right way to fetch a record by id/primary key.

If I use findByPk typescript fails to compile.
If I use findById I get a deprecation warning from Sequelize.

Not sure if this is related to the new API introduced by Sequelize 4

Most helpful comment

So is there anything we can do about it?

All 3 comments

Seems like this is a deprecation made as preparation for Sequelize 5.
See: https://github.com/sequelize/sequelize/commit/1bc8b0e82d4635ff22cbd4c048c042fed30a036f
The release (v4.41.0) containing it is 6 days old, so findByPk is not that old in v4 yet.

So is there anything we can do about it?

Was this page helpful?
0 / 5 - 0 ratings