【问题标题】:Typescript Error Class 'Subject<T>' incorrectly extends base class 'Observable<T>'. Types of property 'lift' are incompatibleTypescript 错误类“Subject<T>”错误地扩展了基类“Observable<T>”。属性“电梯”的类型不兼容
【发布时间】:2019-04-01 21:46:13
【问题描述】:

我一直收到这个错误,但我不确定我在哪里搞砸了。 我的“打字稿”:“~2.6.2”版本

Typescript Error

Class 'Subject<T>' incorrectly extends base class 'Observable<T>'. Types of property 'lift' are incompatible. Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'. Type 'Observable<T>' is not assignable to type 'Observable<R>'. Type 'T' is not assignable to type 'R'.


    node_modules/ionic-native/node_modules/rxjs/Subject.d.ts
    */
    export declare class Subject<T> extends Observable<T> implements 
    ISubscription {
    observers: Observer<T>[];

Typescript Error

Class 'WebSocketSubject<T>' incorrectly extends base class 'AnonymousSubject<T>'. Types of property 'lift' are incompatible. Type '<R>(operator: Operator<T, R>) => WebSocketSubject<R>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<T>'. Type 'WebSocketSubject<R>' is not assignable to type 'Observable<T>'. Types of property 'operator' are incompatible. Type 'Operator<any, R>' is not assignable to type 'Operator<any, T>'. Type 'R' is not assignable to type 'T'.

    node_modules/ionic- 
    native/node_modules/rxjs/observable/dom/WebSocketSubject.d.ts
    */
    export declare class WebSocketSubject<T> extends AnonymousSubject<T> {
    url: string;

离子框架:3.9.2

离子原生:^2.9.0

Ionic 应用脚本:3.2.0

Angular 核心:5.2.11

Angular 编译器 CLI:5.2.11

节点:8.12.0

操作系统平台:macOS

导航平台:MacIntel

用户代理:Mozilla/5.0(Macintosh;Intel Mac OS X 10_14_0)

这是我的 package.json

{
"name": "458",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/base64": "^4.16.0",
"@ionic-native/core": "~4.12.0",
"@ionic-native/image-picker": "^4.16.0",
"@ionic-native/splash-screen": "~4.12.0",
"@ionic-native/status-bar": "~4.12.0",
"@ionic/pro": "2.0.3",
"@ionic/storage": "2.2.0",
"angularfire2": "^5.0.2",
"com-badrit-base64": "^0.2.0",
"cordova-android": "7.0.0",
"cordova-ios": "4.5.5",
"cordova-plugin-camera": "^4.0.3",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.2.0",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-telerik-imagepicker": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.3",
"firebase": "^5.5.6",
"ionic": "^4.1.2",
"ionic-angular": "3.9.2",
"ionic-img-viewer": "^2.9.0",
"ionic-native": "^2.9.0",
"ionicons": "3.0.0",
"rxjs": "^5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.0",
"typescript": "~2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
  "cordova-plugin-telerik-imagepicker": {
    "PHOTO_LIBRARY_USAGE_DESCRIPTION": "your usage message"
  },
  "cordova-plugin-whitelist": {},
  "cordova-plugin-statusbar": {},
  "cordova-plugin-device": {},
  "cordova-plugin-splashscreen": {},
  "cordova-plugin-ionic-webview": {},
  "cordova-plugin-ionic-keyboard": {},
  "com-badrit-base64": {},
  "cordova-plugin-file": {},
  "cordova-plugin-camera": {}
 },
 "platforms": [
  "ios",
  "android"
 ]
 }
 }

【问题讨论】:

  • 您似乎安装了两个不兼容的 rxjs 副本。您能否将您的 package.json 文件添加到问题中,以便我们了解这是如何发生的?
  • @MattMcCutchen 我刚刚添加了我的 package.json 。谢谢
  • 好的,我可以在 node_modules/rxjs (5.5.12) 和 node_modules/ionic-native/node_modules/rxjs (5.0.1) 看到不兼容的 rxjs 副本,但我不确定解决此问题的正确方法.希望你能从熟悉 Ionic 的人那里得到帮助。如果您能够删除 ionic-native 软件包并仅依赖已安装的较新的 @ionic-native/... 软件包,那可能会有所帮助。

标签: angular typescript ionic-framework ionic3


【解决方案1】:

尝试添加:

“noStrictGenericChecks”:真

到您的 tsconfig.json 文件;

【讨论】:

    【解决方案2】:

    How do I get around this "Subject incorrectly extends Observable" error in TypeScript 2.4 and RxJS 5.x?

    这可能会有所帮助。如果不是,请尝试在编译器选项中将 skipLibCheck 设置为 false。

    【讨论】:

    • { "compilerOptions": { "noStrictGenericChecks": true } }
    猜你喜欢
    • 2018-01-18
    • 2017-12-01
    • 2017-12-07
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多