We are currently working on an Ionic project that consists of several pages and a single custom provider named request.ts. The issue we are facing is that whenever we launch it using the command ionic serve --lab, the compilation fails (with the error pointing to the headers in the http.post method from the request.ts file). To resolve this, we have to manually open the app.module.ts file and save it, after which everything works fine.
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/map';
@Injectable()
export class RequestProvider {
constructor(public http: Http) {
console.log('Hello RequestProvider Provider');
}
getSomeResponce(callBack) {
this.http.post(
"some.domain.net/some/service",
{ "argument1": "1", "argument2": "2"},
{ headers: { "Content-Type" : "application/json" } }
).toPromise()
.then(res => callBack(res));
}
}
The provider is imported into app.module.ts as follows:
import { RequestProvider } from '../providers/request/request';
Upon the first launch, we encounter the following error:
Typescript Error Argument of type '{ headers: { "Content-Type": string; }; }' is not assignable to parameter of type 'RequestOptionsArgs'. Types of property 'headers' are incompatible. Type '{ "Content-Type": string; }' is not assignable to type 'Headers'. Object literal may only specify known properties, and '"Content-Type"' does not exist in type 'Headers'.
While this issue may seem minor, it is bothersome, and there is concern that it could potentially be indicative of larger problems in the future.