loopbackio / loopbackio/loopback-next
Error: Definition of model property is missing `type` when circularly referenced with @property()
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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