[英]Typescript Error: Type 'any' is not a constructor function type
I am currently trying out Angular 2 in combination with Ionic 2 so I am a bit new to TypeScript. 我目前正在尝试将Angular 2与Ionic 2结合使用,所以我对TypeScript有点新意。 Basically I was implementing a RESTService and I wanted to make the Rest Class abstract. 基本上我正在实现一个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);
}}
And here is the class which extends from the RESTService: 这是从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 "";
}}
But I always get an Type 'any' is not a constructor function type error at the line " export class RESTServiceJourney extends RESTService ". 但我总是在“ 导出类RESTServiceJourney扩展RESTService ”行中得到一个类型'any'不是构造函数类型错误。 I searched through Google and Stackoverflow and do not know what kind of error this is. 我搜索了谷歌和Stackoverflow,不知道这是什么样的错误。 (I found one on Stackoverflow, but that one has problem with the version.) (我在Stackoverflow上找到了一个,但是那个版本有问题。)
Thanks in Advance! 提前致谢!
I made a mistake when importing the abstract class. 导入抽象类时我犯了一个错误。
I wrote: import { RESTService } from 'restService'; 我在'restService'中写道: import {RESTService};
But had to: import { RESTService } from './restService'; 但不得不: 从'./restService'导入{RESTService};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.