sequelize icon indicating copy to clipboard operation
sequelize copied to clipboard

find** methods with { raw: true } should has another types?

Open DarkOutX opened this issue 2 years ago • 0 comments

Hello. Maybe I don't undestand something, but if I will use ModelStatic methods find*** with options { raw: true }, I get type errors

Example:

const item = await this._model.findOne( { where: { id }, raw: true } );

item should has TModelAttributes type, however it has type Model and looks like it requires call item.get() to receive object

We can find used types is types/model.d.ts where the ReturnValue is fixed M extending Model

  public static findOne<M extends Model>(
      this: ModelStatic<M>,
      options: NonNullFindOptions<Attributes<M>>
  ): Promise<M>;

It works fine for me after adding overloads like this:

  public static findOne<M extends Model>(
      this: ModelStatic<M>,
      options: NonNullFindOptions<Attributes<M>> & { raw: true }
  ): Promise<Attributes<M>>;

So, please, describe, am I doing something wrong? I guess a lot of people use this repo, and a lot of them using raw, but nobody meets the same problem? 0_o

DarkOutX avatar Jun 08 '23 10:06 DarkOutX