loopbackio / loopbackio/loopback-next

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

Open
#10,193 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug sequelize
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

### 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](https://github.com/loopbackio/loopback-next/assets/5942028/efc2f343-f631-40a1-8b16-8256f85ce5ce)

### Reproduction

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and inspect the InclusionFilter and Inclusion types involved in the TypeScript error. Confirm how the Sequelize extension represents nested includes, then verify that required: true is accepted and the reproduction compiles for both relation operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.