loopbackio / loopbackio/loopback-next

Typescript error with Model

Open
#9,444 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### Describe the bug

I am getting type error in find function.

```ts
@model({settings: {strict: false}})
export class URLS extends Model {
@property({
type: 'string',
id: true,
generated: true,
})
id?: string;

@property({
type: 'string',
required: true,
})
title: string;
}

@model({settings: {strict: false}})
export class Links extends Entity {
@property({
type: 'string',
id: true,
generated: true,
})
id?: string;

@property({
type: 'array',
itemType: 'object',
})
urls?: URLS[]
}
```
**Error occurring in below**
```ts
await this.linksRepository.find({
where: {
"urls.id": id
}
})
```

**Error:**

```
Type '{ "urls.id": any; }' is not assignable to type 'Where | undefined'.
Object literal may only specify known properties, and '"urls.id"' does not exist in type 'Where'.
```

### Logs

_No response_

### Additional information

_No response_

### Reproduction

NA

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 by tracing the TypeScript definitions for Where and the repository find entry point used in the example, focusing on how nested array properties are represented. Confirm the intended query behavior and add regression coverage for the shown "urls.id" condition; done means the supported query type-checks without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.