Устранение неполадок TS2345 Ошибка при создании приложения Loopback 4 с аутентификацией JWT - PullRequest
1 голос
/ 20 июня 2019

Я пытаюсь интегрировать аутентификацию JWT в мое приложение loopback 4. Прямо сейчас я следую документации здесь и учебнику по шоппингу , но при регистрации стратегии аутентификации у меня появляется странная ошибка сборки.

Вот мое application.ts:

export class Application extends BootMixin(
  ServiceMixin(RepositoryMixin(RestApplication)),
) {
  constructor(options?: ApplicationConfig) {
    super(options);

    this.setUpBindings();

    this.component(AuthenticationComponent);
    registerAuthenticationStrategy(this, JWTAuthenticationStrategy);
    this.sequence(MySequence);

    // Set up default home page
    this.static('/', path.join(__dirname, '../public'));

    this.component(RestExplorerComponent);

    this.projectRoot = __dirname;
    // Customize @loopback/boot Booter Conventions here
    this.bootOptions = {
      controllers: {
        // Customize ControllerBooter Conventions here
        dirs: ['controllers'],
        extensions: ['.controller.js'],
        nested: true,
      },
    };
  }

  setUpBindings(): void {
    // my bindings
  }
}

Скрипт сборки в моем package.json (с использованием @ loopback / build)

"build": "lb-tsc -p tsconfig.build.json --target es2017 --outDir dist"

Вот ошибка, которую я получаю:

npm run build =>

src/application.ts:71:33 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'Context'.
  Type 'Application' is not assignable to type 'Context'.
    Property 'registry' is protected but type 'Context' is not a class derived from 'Context'.

registerAuthenticationStrategy(this, JWTAuthenticationStrategy);

Я в Windows 10 использую PowerShell.

1 Ответ

0 голосов
/ 24 июля 2019

У меня тоже была такая же проблема.Мне удалось устранить проблему путем обновления зависимости @ loopback / context до последней версии с помощью команды:

npm install --save @loopback/context

При обновленной зависимости ошибка исчезает.

...