The data type 'Subscription' cannot be assigned to the type 'Subscription'

Whenever I try to build my JHipster Angular project, I encounter this error. It occurs right after running the command yarn start

import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { Subscription } from 'rxjs/Subscription';
import { JhiEventManager, JhiParseLinks, JhiAlertService } from 'ng-jhipster';
import { ITEMS_PER_PAGE, Principal } from '../../shared';
import { Observable } from 'rxjs/Observable';
....
private subscription: Subscription;
    private eventSubscriber: Subscription;
...
 ngOnInit() {
        this.subscription = this.route.params.subscribe((params) => {
            this.load(params['id']);
        });
}


> TS90010: Type 'Subscription' is not assignable to type 'Subscription'.
> Two different types with this name exist, but they are unrelated.

Oddly enough, it worked perfectly fine before without any issues. The reason behind this sudden error eludes me.

Answer №1

Consider modifying the following code

import { Subscription } from 'rxjs/Subscription';
import { Observable } from 'rxjs/Observable';

with this alternative

import { Subscription, Observable } from 'rxjs';

Answer №2

Instead of trying to keep track of multiple subscription objects, a better approach is to utilize a single Subject with takeUntil method for managing rxjs subscriptions in Angular.

finalise = new Subject<void>();

this.route.params.subscribe((params) => {
  this.load(params['id']);
}).pipe(takeUntil(this.finalise)); // No need to unsubscribe if finalise emits.

ngOnDestroy() {
  this.finalise.next();
  this.finalise.complete();
}

By implementing this method, you can streamline the management of all subscriptions using just one object within the component.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Timing functions fired with various delays

Within the context of an Angular application, there is a method that utilizes setTimeout to address layout issues with a third-party UI library: setStep(): void { // Workaround to resolve current UI problem. setTimeout(() => { const items ...

What could be the reason for ng serve malfunctioning when the project cli version is v9 and the global cli version is v11

After setting up angular project with cli version 9, I encountered an issue due to having global cli version 11. When attempting to run "ng serve", the following error message appeared: The current version of CLI is designed to work with Angular version ...

Obtain information from a PHP file using AngularJS 2

Can you guide me on how to post data and receive a response from a PHP page in AngularJS 2? I want to send data from auth.js file to session.php for storing the session value. Please show me how to do this using HTTP POST method. retu ...

Ensure that Angular waits for the subscription to be completed before triggering the function to generate an Excel

I've encountered an issue with a function that generates an excel from an API request on my webpage. There's a download button that triggers the downloadCSV() function, which usually works fine except when I click it too quickly while navigating ...

Enhancing JavaScript with TypeScript: implementing functional mixins

I'm in the process of creating functional mixins using TypeScript. Below is the code I have written so far: const flying = (o: object) => { let isFlying = false; return Object.assign({}, o, { fly() { isFlying = true; return thi ...

There seems to be an issue with the OpenAPI generator for Angular as it is not generating the multipart form data endpoint correctly. By default

Here is the endpoint that needs to be addressed: @PostMapping(value = "/file-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public List<FileReference> handleFileUpload( @RequestPart(value = "file", name = "f ...

Enhance your Angular Material Table with split headers and sticky header capabilities

I am having an issue with the header of my Angular Material table. I need help adding a sticky header feature. I tried using sticky: true, but it's not working for my first column since I have hidden it. Additionally, the first row is displaying the ...

Despite passing the same dependency to other services, the dependencies in the constructor of an Angular2 Service are still undefined

To successfully integrate the "org-agents-service" into the "org-agents-component," I need to resolve some dependencies related to the required api-service. Other components and services in the hierarchy are also utilizing this api-service, which acts as a ...

Issue with Ionic 2 where headers are not being properly set before making an HTTP request

I am currently working on a request to my backend system that involves setting up headers and tokens. The code I have written for this process is as follows: loggedIn() { let headers = new Headers(); headers.append('Content-Type', ' ...

Creating a factory function through typhography

I have a dynamically generated list of functions that take an argument and return different values: actions: [ param => ({name: param, value: 2}), param => ({label: param, quantity: 4}), ] Now I am looking to create a function that will gen ...

What could be causing the error message "why can't shows read property

Within my Ionic-Angular application, I have successfully loaded the content from the database and printed it on the console. However, I am facing an issue where I cannot bind this content to the view. The error message that appears is displayed in https:// ...

Creating a new model in TypeScript may encounter a declaration issue with getting

I may just be overlooking something, but I have the following model: import { Brand } from './brand'; import { Plan } from './plan'; import { Venue } from './venue'; export class Subscription { id: number; brandId: number ...

"String representation" compared to the method toString()

Currently, I am in the process of writing unit tests using jasmine. During this process, I encountered an issue with the following code snippet: let arg0: string = http.put.calls.argsFor(0) as string; if(arg0.search(...) This resulted in an error stating ...

Should a MEAN stack app require the use of two servers in order to run?

Currently, I am in the process of developing a MEAN stack application which involves using MongoDB, ExpressJs, Angular 6, and NodeJs. One issue I am facing is determining whether two servers will be necessary to run the app simultaneously. Specifically, o ...

finding corresponding key in ngFor

I am curious to see if it is possible to match a key in *ngfor. Here is an example of my code on StackBlitz. However, when I try this method, it only displays No data. HTML <ul> <li *ngFor="let course of courses; index as i"> ...

Downloading videos from WebRTC getDisplayMedia in Angular 8 is not supported

Currently utilizing the NPM package in conjunction with Angular 8 found here: [ https://www.npmjs.com/package/webrtc-adapter ] to mimic the WebRTC getDisplayMedia functionality showcased here: [ ] I have successfully managed to initiate and terminate a r ...

Error: Unable to access 'nativeElement' property from undefined object when trying to read HTML element in Angular with Jasmine testing

There is a failure in the below case, while the same scenario passes in another location. it('login labels', () => { const terms = fixture.nativeElement as HTMLElement; expect(terms.querySelector('#LoginUsernameLabel')?.tex ...

What's the best way to verify if a user is already authenticated in Angular Firebase?

Creating a security measure to redirect unauthorized users to the login page using AngularFireAuth is crucial. In the past, a popular method involved storing tokens in local or session storage and checking for their existence when the guard was triggered. ...

React component is not properly updating the state setter value

useState() is unable to store file objects. I have included comments within the code snippet below to clarify the issue: const [file, setFile] = useState<File>() const onChange = async ( imageList: ImageListType, addUpdateIndex: number[] | ...

Refresh causing Angular routing failure due to identical names for Angular route and server route

I've encountered an interesting issue with Angular (version 5) involving the setup of routes in my application. Here's how they are configured: {path: 'calendar', canActivate: [AuthGuard], component: ProjectsComponent } {path: 'm ...