Open joschne opened 3 years ago
After further investigation, I found a workaround.
// use:
@hasOne(() => Bar)
bar?: Bar;
// instead of
@property(Bar)
bar?: Bar;
// and expose the Model with relations on Controller endpoint so:
@get('/bar')
@response(200)
bar(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Bar, {includeRelations: true}),
},
},
})
bar: Bar,
): string {
return 'ok';
}
See: https://github.com/joschne/loopback-next/tree/my-issue-1-workaround
Steps to reproduce
Create new lb4 app, then:
Create model Foo
Create model 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_typeExpected Behavior
Should start, as it does when having self referenced model, like e.g.:
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