私は Angular 2 で中央の ExceptionHandler を実装しようとしています。SO を検索したところ、以下のようなこの主題に関するいくつかのトピックが見つかりました。
モジュール「angular2/angular2」にはエクスポートされたメンバー「ExceptionHandler」がありません
angularjsでexceptionHandlerを適切に上書きする方法は?
しかし、このトピックは時代遅れのようです。
私はAngular 2 RC5を使用しており、こちらのドキュメントに従って、実装しようとしました:
import { ExceptionHandler } from '@angular/core';
export class CustomExceptionHandler implements ExceptionHandler {
call(error:any, stackTrace:any = null, reason:string = null) {
// do something with the exception
}
}
しかし、「TS2420 - CustomExceptionHandler がインターフェイス ExceptionHandler を正しく実装していません。タイプ 'CustomExceptionHandler' にプロパティ '_logger' がありません。
私はTSの初心者ですが、Javaで10年間プログラミングしています。
実際、IDE (IntelliJ) で ExceptionHandler をクリックすると、コードはインターフェイスではなくクラスに追従します。
export declare class ExceptionHandler {
private _logger;
private _rethrowException;
constructor(_logger: any, _rethrowException?: boolean);
static exceptionToString(exception: any, stackTrace?: any, reason?: string): string;
call(exception: any, stackTrace?: any, reason?: string): void;
}