如何配置angular库以使用RxJS的正确安装并将其用于本地测试?
我已经能够将我的库构建、链接并导入到我的主应用程序中,但是我的库提供了一个返回RxJs可观测值的服务,我遇到了一个问题,返回类型是库节点_模块中的RxJs可观测值,而不是主应用程序节点_模块中的RxJs可观测值:如何配置angular库以使用RxJS的正确安装并将其用于本地测试?,angular,typescript,rxjs,angular-library,npm-link,Angular,Typescript,Rxjs,Angular Library,Npm Link,我已经能够将我的库构建、链接并导入到我的主应用程序中,但是我的库提供了一个返回RxJs可观测值的服务,我遇到了一个问题,返回类型是库节点_模块中的RxJs可观测值,而不是主应用程序节点_模块中的RxJs可观测值: Type 'import("D:/KeySystems-Angular-Packages/node_modules/rxjs/internal/Observable").Observable<boolean>' is not assignable to type 'impo
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)
以及图书馆项目本身:
{
"name": "state-management",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^7.0.0",
"@angular/core": "^7.0.0",
"rxjs": "^6.5"
}
}
库的工作区的tsconfig:
{
"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/*"
]
}
}
}
{
"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:
{
"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/*"
]
}
}
}
{
"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路径中-我假设在库中,但这对我不起作用,所以我尝试了这两种方法,正如您在上面看到的
这是一个问题,因为这会导致错误:
getBusinessClaims(): Observable<IBusinessClaims> {
return this.stateService.get<IBusinessClaims>(ClaimType.Business);
}
getBusinessClaims():可观察{
返回此.stateService.get(ClaimType.Business);
}
这个错误听起来好像导入应该来自不同的位置,但表面上是因为版本混合匹配。我想最好将RxJs包锁定在次要位置,而不是主要位置,以避免出现这种情况。也许您可以将apps tsconfig中的RxJs路径更改为安装在node_modules文件夹中,该包从该文件夹获取rx。然后rxjs路径将再次对齐。但对于实际构建,我不建议这样做(您基本上不知道有什么版本)。