Angular 编译过程中最新rxjs出错

Angular 编译过程中最新rxjs出错,angular,rxjs,Angular,Rxjs,我是angular的新手,我正在尝试将angular 4升级为最新的angular, 我试图使可重用的类方法,在许多服务和组件上使用它 假设此文件名为: ./base-services.services.ts: 我使用这些基本服务来扩展我提供的所有服务 ./getData.services.ts: 在组件上: updateValue() { this.legalOrderService.getCart().subscribe(response => { if (resp

我是angular的新手,我正在尝试将angular 4升级为最新的angular, 我试图使可重用的类方法,在许多服务和组件上使用它

假设此文件名为:

./base-services.services.ts:

我使用这些基本服务来扩展我提供的所有服务

./getData.services.ts:

在组件上:

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");
      }
    });
  }
在服务的组件上使用subscribe是否有错

在这之后,我得到如下错误:

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'.

我在代码中看到的一个问题是,您不需要多次订阅,只需从getDataParam方法中删除订阅,因为您已经在组件中订阅了

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

您正在尝试订阅以下订阅:

首先尝试在getDataParam中订阅 然后尝试在updateValue中再次订阅 从getDataParam中删除订阅:


所以我不应该订阅那个可重用类?然后把它订阅到一个组件中?@ZumDummi不。只要订阅你的组件就行了component@ZumDummi您可以在可重用类上应用其他操作符,如map,而不是subscribe,您可以给我一个在可恢复类上使用map的示例吗?@ZumDummi like this return this.http.posturl,data.pipemapres=>res,catchErrorthis.HandleErrors我不应该订阅那个可重用类吗?然后把它订阅到一个组件中?是的。为组件获取数据时,订阅组件是一个很好的经验法则。我们是否也应该使用map?您希望映射什么?以获得json结果
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'.
getDataParam(url: any, params: any) {
    return this.http
      .get(url, { params: params })
      .pipe(catchError(this.handleError));
  }
getDataParam(url: any, params: any) {
    return this.http
      .get(url, { params: params })
      .pipe(catchError(this.handleError));
  }