loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.96k stars 1.07k forks source link

[@loopback/sequelize] Typescript error when using the "required" property with Sequelize #10193

Open KalleV opened 11 months ago

KalleV commented 11 months ago

Describe the bug

When trying to use the new "required: true" to use an Inner Join instead of a Left Join, it leads to a Typescript error:

Type '{ relation: string; scope: { where: { id: number; }; }; required: true; }'
is not assignable to type 'InclusionFilter'.
  Object literal may only specify known properties, and 'required'
does not exist in type 'Inclusion'.

53           required: true

This also happens for nested relation operations such as:

myRepository(foreignKey).find({
  include: [
    {
      // ...
      required: true
    }
  ]
}

Logs

No response

Additional information

sequelize_extension_required_property_ts_error

Reproduction

https://codesandbox.io/p/devbox/loopback-sequelize-types-24l36w

samarpanB commented 10 months ago

@KalleV is this fixed with #10192 or do we need any more update for this ? Can you please elaborate if anything is pending here ?

KalleV commented 10 months ago

@samarpanB It is partially fixed by https://github.com/loopbackio/loopback-next/pull/10192. It will still give an error for the required property on nested relation operations like:

myRepository(foreignKey).find({
  include: [
    {
      // ...
      required: true
    }
  ]
}

Without global declaration merging or modifying the original Inclusion interface, I tried a couple of approaches for this, like defining a custom HasManyThroughFactory interface (e.g., https://github.com/loopbackio/loopback-next/pull/10192#discussion_r1402763654).