loopbackio / loopbackio/loopback-next

Error: Definition of model property is missing `type` when circularly referenced with @property()

Open
#7,482 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

Steps to reproduce

Create new lb4 app, then:

Create model Foo

@model()
export class Foo {

  @property()
  name?: string;

  @property({type: Bar})
  bar?: Bar;

  constructor(data?: Partial<Foo>) {
  }
}

Create model Bar

@model()
export class Bar {

  @property()
  name?: string;

  @property({type: Foo})
  foo?: Foo;

  constructor(data?: Partial<Bar>) {
  }
}

Start the application.

Current Behavior

Cannot start the application. Error: The definition of model property Foo.bar is missing type field and TypeScript did not provide any design-time type. Learn more at https://loopback.io/doc/en/lb4/Error-codes.html#cannot_infer_property_type

Expected Behavior

Should start, as it does when having self referenced model, like e.g.:

@model()
export class Baz {

  @property()
  name?: string;

  @property({type: Baz})
  baz?: Baz;

  constructor(data?: Partial<Baz>) {
  }
}

Link to reproduction sandbox

https://github.com/joschne/loopback-next/tree/my-issue-1

Additional information

darwin x64 12.8.1
@loopback/example-todo@3.11.0 /Users/admin/Code/Playground/bugs/loopback-next/examples/todo
├── UNMET DEPENDENCY @loopback/boot@^3.4.0
├── UNMET DEPENDENCY @loopback/core@^2.16.0
├── UNMET DEPENDENCY @loopback/repository@^3.6.0
├── UNMET DEPENDENCY @loopback/rest@^9.3.0
├── UNMET DEPENDENCY @loopback/rest-explorer@^3.3.0
├── UNMET DEPENDENCY @loopback/service-proxy@^3.2.0
├── loopback-connector-rest@4.0.1
npm ERR! missing: @loopback/boot@^3.4.0, required by @loopback/example-todo@3.11.0
npm ERR! missing: @loopback/core@^2.16.0, required by @loopback/example-todo@3.11.0
npm ERR! missing: @loopback/repository@^3.6.0, required by @loopback/example-todo@3.11.0
npm ERR! missing: @loopback/rest@^9.3.0, required by @loopback/example-todo@3.11.0
npm ERR! missing: @loopback/rest-explorer@^3.3.0, required by @loopback/example-todo@3.11.0
npm ERR! missing: @loopback/service-proxy@^3.2.0, required by @loopback/example-todo@3.11.0

Related Issues

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 reproducing the error when the application starts with the Foo and Bar models from the issue, using the linked reproduction sandbox. Trace model property type inference for the circular @property() references; done means the application starts and the Foo/Bar case behaves like the self-referenced Baz example.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.