Skip to content

[Repository] Error after RepositoryMixin integration #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arash01 opened this issue Dec 13, 2017 · 4 comments
Closed

[Repository] Error after RepositoryMixin integration #799

arash01 opened this issue Dec 13, 2017 · 4 comments

Comments

@arash01
Copy link
Contributor

arash01 commented Dec 13, 2017

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);
  }
}
@raymondfeng
Copy link
Contributor

This import statement seems to fix your problem:

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

@raymondfeng
Copy link
Contributor

See microsoft/TypeScript#15870 for explanations.

@arash01
Copy link
Contributor Author

arash01 commented Dec 14, 2017

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

@trusktr
Copy link

trusktr commented Dec 21, 2019

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. microsoft/TypeScript#35822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants