Reputation: 212
I am currently trying out Angular 2 in combination with Ionic 2 so I am a bit new to TypeScript. Basically I was implementing a RESTService and I wanted to make the Rest Class abstract.
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:
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". I searched through Google and Stackoverflow and do not know what kind of error this is. (I found one on Stackoverflow, but that one has problem with the version.)
Thanks in Advance!
Upvotes: 3
Views: 3436
Reputation: 212
I made a mistake when importing the abstract class.
I wrote: import { RESTService } from 'restService';
But had to: import { RESTService } from './restService';
Upvotes: 3