import {Request, RestBindings, get, ResponseObject, post} from '@loopback/rest';
import {inject} from '@loopback/context';
import {repository, DefaultCrudRepository, Entity} from '@loopback/repository';
import {TestRepository} from '../repositories';
import {Test} from '../models';
import uuid = require('uuid');
/**
* OpenAPI response for ping()
*/
const PING_RESPONSE: ResponseObject = {
description: 'Ping Response',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
greeting: {type: 'string'},
date: {type: 'string'},
url: {type: 'string'},
headers: {
type: 'object',
properties: {
'Content-Type': {type: 'string'},
},
additionalProperties: true,
},
},
},
},
},
};
/**
* A simple controller to bounce back http requests
*/
export class PingController {
constructor(
@inject(RestBindings.Http.REQUEST) private req: Request,
@repository(TestRepository) private repo: TestRepository,
) {}
// Map to `GET /ping`
@get('/ping', {
responses: {
'200': PING_RESPONSE,
},
})
ping(): object {
// Reply with a greeting, the current time, the url, and request headers
return {
greeting: 'Hello from LoopBack',
date: new Date(),
url: this.req.url,
headers: Object.assign({}, this.req.headers),
};
}
@post('/test')
async test() {
return await this.create(
new Test({_id: uuid(), test: 'test'}),
this.repo,
);
}
async create<T extends Entity, U>(
instance: T,
// tslint:disable-next-line: no-shadowed-variable
repository: DefaultCrudRepository<T, U>,
) {
return await repository.create(instance);
}
}
Error:
$ npm start
[email protected] prestart /home/jakub/Projects/luther/pro/test
npm run build
[email protected] build /home/jakub/Projects/luther/pro/test
lb-tsc es2017 --outDir dist
error TS2321: Excessive stack depth comparing types 'HasManyRepository>' and 'HasManyRepository>'.
error TS2321: Excessive stack depth comparing types 'ModelData>' and 'ModelData>'.
Found 2 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: lb-tsc es2017 --outDir dist
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jakub/.npm/_logs/2019-08-29T13_20_23_571Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] prestart: npm run build
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jakub/.npm/_logs/2019-08-29T13_20_23_593Z-debug.log
Successful execution of npm start.
Error occurs after update from typescript 3.5.* to 3.6.*.
Error occurs after update from typescript 3.5.* to 3.6.*.
For now, don't upgrade to TS 3.6.x.
wowza, it seem that many of my project dependencies are required typescript ^3.6, so i can't avoid upgrading to 3.6.x
This will be fixed by https://github.com/strongloop/loopback-next/pull/3614
Closing as fixed, please let us know if the problem still persists.
Most helpful comment
This will be fixed by https://github.com/strongloop/loopback-next/pull/3614