fetchVerificationCode(phoneNumber) {
let endpoint = `${remote}/secure/verify/${phoneNumber}`;
return this._http.get(endpoint)
.toPromise()
.then(data => {
console.log(data.response); <--- PROBLEM
});
}
When the code above is executed, it expects a property named response in the returned data. However, there is an issue raised by the typescript compiler:
Error TS2339: Property 'response' does not exist on type 'DataResponse'.
Trying to solve this, I attempted to define an interface like so:
interface DataResult<T> {
response: string
}
and then implementing it as:
this.fetchVerificationCode('1111111') {
let endpoint = `${remote}/secure/verify/${phoneNumber}`;
return this._http.get(endpoint)
.toPromise()
.then( (data: DataResult<any> )=> {
console.log(data.response); <--- PROBLEM
});
However, this led to the error message:
Error TS2345: Argument of type '(data: DataResult<any>) => void' is not compatible with parameter of type '(value: DataResponse) => void | PromiseLike<void>'.
Types 'data' and 'value' are not compatible.
Type 'DataResponse' is missing the 'response' property found in type 'DataResult<any>'.