Search code examples
nativescript-angular

Type 'Subscription' is missing the following properties from type 'typeof Subscription': prototype, EMPTY


import { Component, OnInit, OnDestroy, ViewChild, AfterViewInit, ChangeDetectorRef } from "@angular/core";
import { UIService } from "./shared/ui.service";
import { Subscription } from "rxjs";
import { RadSideDrawerComponent } from "nativescript-ui-sidedrawer/angular";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";

//These are my imports

@Component({
    selector: "ns-app",
    templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit, OnDestroy, AfterViewInit {

    @ViewChild(RadSideDrawerComponent, { static: false }) drawerComponent: RadSideDrawerComponent;

    enteredChallenge: string[] = [];
    private drawerSub = Subscription; //I have put subscription here
    private drawer: RadSideDrawer;

    constructor (private uiService: UIService, private changeDetectionRef: ChangeDetectorRef) {}

    onChallengeInput(enterText: string){
        this.enteredChallenge.push(enterText);
    }

    ngOnInit(){
        this.drawerSub = this.uiService.drawerState.subscribe(
            () => {
                if(this.drawer){
                    this.drawerComponent.sideDrawer.toggleDrawerState();
                }
            }
        );
    }

    ngAfterViewInit(){

        this.drawer = this.drawerComponent.sideDrawer;
        this.changeDetectionRef.detectChanges();
    }

    ngOnDestroy(){
        if(this.drawerSub){
            this.drawerSub.unsubscribe();
        }

    }
 }

I have 2 errors 1 -> Property 'unsubscribe' does not exist on type 'typeof Subscription'. 2 -> Type 'Subscription' is missing the following properties from type 'typeof Subscription': prototype, EMPTY

I have included Subscription and the stuff I need but I don't understand why I still get this error. Can someone help me out?


Solution

  • I also made this simple mistake and couldn't spot the typo. The line:

    private drawerSub = Subscription;
    

    Should be:

    private drawerSub: Subscription;