类型“Subscription”缺少类型“typeof Subscription”中的以下属性:prototype、EMPTY

Vor*_*zie 2 nativescript-angular

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";
Run Code Online (Sandbox Code Playgroud)

//这些是我的导入

@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();
        }

    }
 }
Run Code Online (Sandbox Code Playgroud)

我有 2 个错误 1 ​​-> 类型“typeof Subscription”上不存在属性“unsubscribe”。2 -> 类型“Subscription”缺少类型“typeof Subscription”中的以下属性:prototype、EMPTY

我已经包含了订阅和我需要的东西,但我不明白为什么我仍然收到此错误。有人可以帮我吗?

Edm*_*son 6

我也犯了这个简单的错误,但无法发现拼写错误。该行:

private drawerSub = Subscription;
Run Code Online (Sandbox Code Playgroud)

应该:

private drawerSub: Subscription;
Run Code Online (Sandbox Code Playgroud)