Skip to content

Declaration of 'client' property breaks relations for model #1115

@atassis

Description

@atassis

Package version

@adonisjs/lucid@21.6.1

node -v
v22.14.0
npm -v
11.4.1

Describe the bug

Relationships typings stopped working after updating project, latest version of packages don't work after fresh install. I see TS2339 and TS2345 errors for most of the relations I use in the codebase. Next are examples:

app/services/project_service.ts:103:40 - error TS2339: Property 'associate' does not exist on type 'never'.

103       await estimate.related('client').associate(client);
                                           ~~~~~~~~~

app/services/project_service.ts:104:30 - error TS2345: Argument of type '"generalContractor"' is not assignable to parameter of type 'ExtractModelRelations<Estimate>'.

104       await estimate.related('generalContractor').associate(generalContractor);
                                 ~~~~~~~~~~~~~~~~~~~

app/services/project_service.ts:104:51 - error TS2339: Property 'associate' does not exist on type 'never'.

104       await estimate.related('generalContractor').associate(generalContractor);
                                                      ~~~~~~~~~

It was created a repo with next commands and few file changes without installing or updating anything else.

npm init adonisjs@latest adonisjs-lucid-error-test -- --kit=api --db postgres
cd adonisjs-lucid-error-test/
node ace make:model Task -m
node ace make:model Estimate -m
node ace make:model Project -m
node ace make:model Item -m
node ace make:model Labor -m
node ace make:service ProjectService

I have populated models and service files with the code to address the issue.

Reproduction repo

https://github.com/atassis/adonisjs-lucid-error-test)

Also including console output for initiating an app

npm init adonisjs@latest adonisjs-lucid-error-test -- --kit=api --db postgres

Need to install the following packages:
create-adonisjs@2.4.0
Ok to proceed? (y) y


> npx
> "create-adonisjs" adonisjs-lucid-error-test --kit=api --db postgres


     _       _             _         _ ____
    / \   __| | ___  _ __ (_)___    | / ___|
   / _ \ / _` |/ _ \| '_ \| / __|_  | \___ \
  / ___ \ (_| | (_) | | | | \__ \ |_| |___) |
 /_/   \_\__,_|\___/|_| |_|_|___/\___/|____/


❯ Which authentication guard you want to use · session
❯ Download starter kit (1.98 s)
  Downloaded "github:adonisjs/api-starter-kit"
❯ Install packages (30 s)
  Packages installed using "npm"
❯ Prepare application (915 ms)
  Application ready
❯ Configure Lucid (6.77 s)
  Lucid configured to use "postgres" database
❯ Configure Auth (8.12 s)
  Auth configured to use "session" guard

╭──────────────────────────────────────────────────────────────────╮
│    Your AdonisJS project has been created successfully!          │
│──────────────────────────────────────────────────────────────────│
│                                                                  │
│    ❯ cd adonisjs-lucid-error-test                                │
│    ❯ npm run dev                                                 │
│    ❯ Open http://localhost:3333                                  │
│    ❯                                                             │
│    ❯ Have any questions?                                         │
│    ❯ Join our Discord server - https://discord.gg/vDcEjq6        │
│                                                                  │
╰──────────────────────────────────────────────────────────────────╯

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions