我知道我错过了一些明显的东西。下面是在生产环境中实际运行的伪代码。但是,IDE(IntelliJ IDEA)给了我一个我无法破解的错误。它可以通过 noinspection TypeScriptValidateTypes 来抑制,但是,我真正想知道的是发生了什么:
this.authService.onAuthStateChanged()
.pipe(
withLatestFrom(
this.activatedRoute.queryParams.pipe(
map(params => params['returnUrl'])
)
)
)
.subscribe(([authState, returnUrl]) => {
// [...]
});
我在 subscribe
行遇到的错误:
Argument type ([authState, returnUrl]: readonly [any, any]) => void is not assignable to parameter type Partial<Observer<[(AuthState | undefined), ...unknown[]]>> | undefined
其他相关细节?
// AuthState is just a POJO.
onAuthStateChanged(): BehaviorSubject<AuthState | undefined>
// This is Angular's params object.
// https://angular.io/api/router/Params
export declare type Params = {
[key: string]: any;
};
我正在使用 RxJS ~7.5.0
和 Typescript ~4.7.4
。我也在使用 Angular ^14.2.0
,尽管这确实不是 Angular 问题。
那么,这里应该发生什么? onAuthStateChanged
根据用户是否登录发出 AuthState
或 undefined
。这与名为 returnUrl
的查询参数相结合>,当然是一个字符串
。
现在,语法的工作方式是使用解构赋值签名 ([authState, returnUrl])
来使用两个可观察量 - 至少我认为它是这么叫的。正如我所说,它在现实生活中正确编译和执行,正如其他人在这里所示,在 StackBlitz 上也不会出错。 (更新为与我的环境更加匹配,具有相同的 tslint
、angular.json
等)。
然而,我心爱的 IntelliJ...
我是否正在查看最新版本的 RxJS 中的重大更改:
withLatestFrom
- Generic signatures have changed. Do not explicitly pass generics.
Source: https://rxjs.dev/6-to-7-change-summary#withlatestfrom
这是伟大的,除了它仍然可以编译和运行。所以,有两件事:
- 幕后发生了什么导致 IntelliJ 中出现此错误?
- 如何让它消失?我尝试强行输入所有参数,但无济于事......
最佳答案
问题追踪于WEB-57220 ,请关注更新
在设置 | 中启用 Typescript 语言服务语言和框架 | TypeScript 应该有助于消除错误
关于angular - RxJS、Typescript 和可怕的 'Type Mismatch' 警告/错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73604786/