Loopback-next: TS2321: Excesive stack depth comparing types with repositories and models

Created on 29 Aug 2019  路  5Comments  路  Source: strongloop/loopback-next

Steps to reproduce

  1. Create a blank project
  2. Add a model with _id ID property and test string property
  3. Create mongo datasource
  4. Create mongo-Test repository
  5. replace ping controller with following:
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);
  }
}

Current Behavior

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

Expected Behavior

Successful execution of npm start.

Additional information

Error occurs after update from typescript 3.5.* to 3.6.*.

bug

Most helpful comment

All 5 comments

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

Closing as fixed, please let us know if the problem still persists.

Was this page helpful?
0 / 5 - 0 ratings