繁体   English   中英

Typescript Error:类型'any'不是构造函数类型

[英]Typescript Error: Type 'any' is not a constructor function type

我目前正在尝试将Angular 2与Ionic 2结合使用,所以我对TypeScript有点新意。 基本上我正在实现一个RESTService,我想让Rest Class抽象化。

export abstract class RESTService{

   mHttp: Http;
   mParameters: Parameter[];
   mURL: string;

   constructor (private http: Http, private parameters: Parameter[]){
       this.mHttp = http;
       this.mParameters = parameters;
   }

   // URL of the Rest Service
   abstract getURL() : string;

   // Convert or handle the Response
   handleResponse(rawResponse: Response){
       let body = rawResponse.json();
       return body.data || { };
   }

   // Handle an error 
   abstract handleError(error: any);

   // Do the rest call
   makeCall(): Observable<any> {
       return this.mHttp.get(this.mURL).map(this.handleResponse).catch(this.handleError);
   }}

这是从RESTService扩展的类:

export class RESTServiceJourney extends RESTService{

   constructor(http:Http, parameters:Parameter[]){
       super(http, parameters);
   }

   // URL of the Rest Service
   getURL() : string {
        return "";
   }

   // Convert or handle the Response
   private handleResponse(rawResponse: Response){
       return "";
   }

   // Handle an error 
   private handleError(error: any){
       return "";
   }}

但我总是在“ 导出类RESTServiceJourney扩展RESTService ”行中得到一个类型'any'不是构造函数类型错误。 我搜索了谷歌和Stackoverflow,不知道这是什么样的错误。 (我在Stackoverflow上找到了一个,但是那个版本有问题。)

提前致谢!

导入抽象类时我犯了一个错误。

在'restService'中写道: import {RESTService};

但不得不: 从'./restService'导入{RESTService};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM