Encountering a typescript error when trying to start the app. Not sure where I'm going wrong. It seems like it could be an issue with the rxjs version, but struggling to find the right solution. Seeing incompatible types on my system and not getting responses from observables.
Whenever I run the application, I receive an error, but simply saving the code in the app.component.ts file fixes it.
This is the error I'm facing in the rxjs module https://i.sstatic.net/morLK.png
app.service file
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { retryWithBackoff } from './delay-retry-request';
@Injectable()
export class AppService {
searchText: string;
constructor(private http: HttpClient) {}
// Declaring Observable of type any here
// Getting incompatible types
getLanguages(): Observable<any> {
return <Observable<any>>this.http.get('langs').pipe(
// Error occurs here
retryWithBackoff(1000, 3)
);
}
getSystemData(): Observable<any> {
return <Observable<any>>this.http.get('system').pipe(
// Issue persists here
retryWithBackoff(1000, 3)
----------
**enter image description here**
);
}
getInitialData(): Observable<any> {
return <Observable<any>>this.http.get('initialData').pipe(
// Error still present here
retryWithBackoff(1000, 3)
);
}
}
**package.json File**
{
"name": "fmcg-digital-distribution",
"version": "0.0.1",
"authorquot: "Ionic Framework",
"homepagequot: "http://ionicframework.com/",
"privatequot: true,
"dependenciesquot: {
// Dependencies listed here
},
"devDependenciesquot: {
// Dev dependencies listed here
},
"descriptionquot: "An Ionic project",
"configquot: {
"ionic_webpackquot: "./config/webpack.config.js"
}
}
retryWithbackoff
import { of } from 'rxjs/observable/of';
import { delay, mergeMap, retryWhen } from 'rxjs/operators';
// Function for displaying error message
const DEFAULT_MAX_RETRIES = 5;
const DEFAULT_BACKOFF = 1000;
export function retryWithBackoff(delayMs: number, maxRetry = DEFAULT_MAX_RETRIES, backoffMs = DEFAULT_BACKOFF) {
let retries = maxRetry;
return (src: Observable<any>) =>
src.pipe(
retryWhen((errors: Observable<any>) => errors.pipe(
mergeMap(error => {
if (retries-- > 0) {
const backoffTime = delayMs + (maxRetry - retries) * backoffMs;
return of(error).pipe(delay(backoffTime));
}
})
))
);
}