loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

[Repository] Error after RepositoryMixin integration

Open ashdns opened this issue 8 years ago • 4 comments

Hi, I started getting these error messages since I integrated RepositoryMixin.

src/application.ts(10,41): error TS4020: 'extends' clause of exported class 'MyApplication' has or is using private name 'Class'.

src/application.ts(10,41): error TS4020: 'extends' clause of exported class 'MyApplication' has or is using private name 'Repository'.

Here is my application.ts code:

import {Application, ApplicationConfig} from '@loopback/core';
import {AuthenticationComponent} from '@loopback/authentication';
import {RestComponent} from '@loopback/rest';
import {DataSourceConstructor, RepositoryMixin} from '@loopback/repository';
import {UserController} from "./controllers";
import {UserRepository} from './repositories';
import {MySequence} from "./auth-sequence";
import {db} from './datasources/mysql.datasource';

export class MyApplication extends RepositoryMixin(Application) {

  constructor(options?: ApplicationConfig) {
    // Allow options to replace the defined components array, if desired.
    options = Object.assign(
      {},
      {
        components: [AuthenticationComponent, RestComponent],
        rest: {
          sequence: MySequence
        }
      },
      options,
    );
    super(options);
    this.setupRepositories();
    this.setupControllers();
  }

  setupRepositories() {
    const datasource = this.options && this.options.datasource ? new DataSourceConstructor(this.options.datasource) : db;
    this.bind('datasource').to(datasource);
    this.repository(UserRepository);
  }

  setupControllers() {
    this.controller(UserController);
  }
}

ashdns avatar Dec 13 '17 07:12 ashdns

This import statement seems to fix your problem:

import {DataSourceConstructor, RepositoryMixin, Repository, Class} from '@loopback/repository';

raymondfeng avatar Dec 13 '17 20:12 raymondfeng

See https://github.com/Microsoft/TypeScript/issues/15870 for explanations.

raymondfeng avatar Dec 13 '17 20:12 raymondfeng

It would be great if you add this fix into readme file as well. thanks :)

ashdns avatar Dec 14 '17 02:12 ashdns

Regarding the all-too-common "has or is using private name" error, I've opened a request to fix issues like these in TypeScript by bringing declaration files to parity with language features. https://github.com/microsoft/TypeScript/issues/35822

trusktr avatar Dec 21 '19 20:12 trusktr