首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何配置我的angular库来使用正确安装的RxJS llinking来进行本地测试?

我如何配置我的angular库来使用正确安装的RxJS llinking来进行本地测试?
EN

Stack Overflow用户
提问于 2020-01-17 22:41:07
回答 1查看 754关注 0票数 0

我已经能够构建、链接和导入我的库到我的主应用程序中,但是我的库提供了一个返回RxJs可观察对象的服务,并且我遇到了一个问题,返回类型是在库node_modules中找到的RxJs可观察对象,而不是主应用程序node_modules:

代码语言:javascript
复制
Type 'import("D:/KeySystems-Angular-Packages/node_modules/rxjs/internal/Observable").Observable<boolean>' is not assignable to type 'import("d:/KeySystems-WebCustomerPortal/node_modules/rxjs/internal/Observable").Observable<boolean>'.
  Types of property 'source' are incompatible.
    Type 'import("D:/KeySystems-Angular-Packages/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("d:/KeySystems-WebCustomerPortal/node_modules/rxjs/internal/Observable").Observable<any>'.ts(2322)

下面是我的Angular库的工作区的package.json:

代码语言:javascript
复制
{
  "name": "key-systems-core-workspace",
  "version": "0.0.0",
  "scripts": {},
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@types/cpx": "^1.5.0",
    "@types/npm": "^2.0.31",
    "core-js": "^2.5.4",
    "cpx": "^1.5.0",
    "npm": "^6.12.1",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular-devkit/build-ng-packagr": "~0.13.0",
    "@angular/cli": "~7.3.5",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ng-packagr": "^4.2.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tsickle": ">=0.34.0",
    "tslib": "^1.9.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

和库项目本身:

代码语言:javascript
复制
{
  "name": "state-management",
  "version": "0.0.1",
  "peerDependencies": {
    "@angular/common": "^7.0.0",
    "@angular/core": "^7.0.0",
    "rxjs": "^6.5"
  }
}

库的工作区的tsconfig:

代码语言:javascript
复制
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "state-management": [
        "dist/state-management"
      ],
      "state-management/*": [
        "dist/state-management/*"
      ],
      "rxjs": [
        "./node_modules/rxjs"
      ],
      "rxjs/*": [
        "./node_modules/rxjs/*"
      ]
    }
  }
}

我的应用程序的tsconfig:

代码语言:javascript
复制
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "@shared/*": ["app/shared/*"],
      "rxjs": [
        "node_modules/rxjs"
      ],
      "rxjs/*": [
        "node_modules/rxjs/*"
      ]
    },
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types",
      "src/global-types/typings.d.ts"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "resolveJsonModule": true, // allow us to directly import json like modules
    "esModuleInterop": true, // quiets error about default exports when importing json,
    "downlevelIteration": true // supports downleveling iteration to es5 such as Sets
  }
}

据我所知,对等依赖应该在tsconfig路径中-我假设在库中,但这对我不起作用,所以我尝试了这两个路径,正如你在上面看到的。

这是一个问题,因为这会导致错误:

代码语言:javascript
复制
getBusinessClaims(): Observable<IBusinessClaims> {
    return this.stateService.get<IBusinessClaims>(ClaimType.Business);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-21 23:13:15

错误听起来像是导入应该来自不同的位置,但实际上是因为版本混合匹配。为了避免这种情况,我想把RxJs包锁定在次要的而不是主要的上会是个好主意。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59789557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档