loopbackio / loopbackio/loopback-next

TypeScript error: Property 'toString' does not exist in has-many-through.inclusion-resolver.ts after upgrading to @loopback/repository@8.0.2

Open
#11,123 1 comment 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

Steps to reproduce

  1. Upgrade @loopback/repository from 6.1.5 to 8.0.2 (other LoopBack packages remain at compatible versions).
  2. Build the project with TypeScript strict mode enabled.

Current behavior

TypeScript compilation fails with:
node_modules/@loopback/repository/src/relations/has-many/has-many-through.inclusion-resolver.ts:255:36 - error TS2339: Property 'toString' does not exist on type 'NonNullable<(Target & TargetRelations)[Extract<keyof Target, string>]>'.

255 targetEntity[targetKey]?.toString() ?? targetEntity[targetKey],


node_modules/@loopback/repository/src/relations/has-many/has-many-through.inclusion-resolver.ts:269:35 - error TS2339: Property 'toString' does not exist on type 'NonNullable<(Through & ThroughRelations)[Extract<keyof Through, string>]>'.

269 x => x[throughKeyTo]?.toString() ?? x[throughKeyTo],

### Logs

```shell

```

### Additional information

_No response_

### Reproduction

import {Entity, model, property, hasMany} from '@loopback/repository';  @model() export class Category extends Entity {   @property({id: true})   id: number;    @hasMany(() => Product, {through: {model: () => CategoryProduct}})   products?: Product[]; }  @model() export class Product extends Entity {   @property({id: true})   id: number; }  @model() export class CategoryProduct extends Entity {   @property()   categoryId: number;    @property()   productId: number; }

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

Open src/relations/has-many/has-many-through.inclusion-resolver.ts and inspect the expressions at lines 255 and 269 that trigger TS2339 under strict mode. Reproduce the upgrade and strict TypeScript build with the Category, Product, and CategoryProduct models; done means the build succeeds without these errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.