ошибка в новейшем rxjs во время компиляции - PullRequest
0 голосов
/ 24 мая 2019

Я новичок в Angular, и я пытаюсь обновить Angular 4 до новейшего Ngular, я пытался сделать многоразовым метод класса, чтобы использовать его на многих сервисах и компоненте

допустим, этот файл называется:

. / Base-services.services.ts :

getDataParam(url: any, params: any) {
    return this.http
      .get(url, { params: params })
      .pipe(catchError(this.handleError))
      .subscribe(response => response);
  }

  createData(url: any, data: any) {
    return this.http
      .post(url, data)
      .pipe(catchError(this.handleError))
      .subscribe(response => response);
  }

и я использую эти базовые сервисы для расширения на все сервисы, которые я делаю

. / GetData.services.ts :

export class LegalorderService extends BaseService {
  private token: string;

  constructor(http: HttpClient, auth: AuthService) {
    super(http);
    auth.isAuthenticated();
    this.token = auth.token;
  }

      getCart() {
         let params = { access_token: this.token };
         return this.getDataParam(
         Configuration.BASE_URL + Configuration.GET_SAVED_CART,
        params
         );
      }
}

и на компоненте:

updateValue() {
    this.legalOrderService.getCart().subscribe(response => {
      if (response.message != "ERROR") {
        this.localStorageService.store("legalOrder", response.result);
        this.localStorageService.store(
          "cartItems",
          response.result.order_details
        );
        this.cartTotal = this.localStorageService.retrieve("cartItems");
      }
    });
  }

я неправильно использую подписку на этот компонент из служб ??

и после этого я получаю сообщение об ошибке:

ERROR in node_modules/rxjs/internal/Subscription.d.ts(16,3): error TS2374: Duplicate string index signature.
    node_modules/rxjs/internal/Subscription.d.ts(17,3): error TS2393: Duplicate function implementation.
    node_modules/rxjs/internal/Subscription.d.ts(17,44): error TS1183: An implementation cannot be declared in ambient contexts.
    node_modules/rxjs/internal/Subscription.d.ts(20,3): error TS2393: Duplicate function implementation.
    node_modules/rxjs/internal/Subscription.d.ts(20,44): error TS1183: An implementation cannot be declared in ambient contexts.
    node_modules/typescript/lib/lib.es5.d.ts(124,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(127,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(130,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(133,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(139,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(145,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'string'.
    node_modules/typescript/lib/lib.es5.d.ts(151,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'string'.

Ответы [ 2 ]

1 голос
/ 24 мая 2019

Вы пытаетесь подписаться на подписку:

  • Сначала вы пытаетесь подписаться на getDataParam
  • Затем вы пытаетесь снова подписаться на updateValue

Удалить subscribe из getDataParam:

getDataParam(url: any, params: any) {
    return this.http
      .get(url, { params: params })
      .pipe(catchError(this.handleError));
  }
0 голосов
/ 24 мая 2019

Одна проблема, которую я вижу в вашем коде, заключается в том, что вам не нужно подписываться несколько раз, просто удалите подписку из метода getDataParam, потому что вы уже подписываетесь в компоненте.

getDataParam(url: any, params: any) {
    return this.http
      .get(url, { params: params })
      .pipe(catchError(this.handleError));
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...