It's clear that I'm overlooking something obvious. The pseudo code below works perfectly in production, but my IDE (IntelliJ IDEA) is throwing an error that I can't solve. I can suppress it with
noinspection TypeScriptValidateTypes
, but I really want to understand what's causing it:
this.authService.onAuthStateChanged()
.pipe(
withLatestFrom(
this.activatedRoute.queryParams.pipe(
map(params => params['returnUrl'])
)
)
)
.subscribe(([authState, returnUrl]) => {
// [...]
});
The error message on the subscribe
line states:
Argument type ([authState, returnUrl]: readonly [any, any]) => void is not assignable to parameter type Partial
> | undefined
Additional relevant information?
// AuthState is just a plain old JavaScript object.
onAuthStateChanged(): BehaviorSubject<AuthState | undefined>
// This is Angular's params object.
// https://angular.io/api/router/Params
export declare type Params = {
[key: string]: any;
};
I'm using RxJS ~7.5.0
, and Typescript ~4.7.4
. My Angular version is ^14.2.0
, although this issue doesn't seem specific to Angular.
So, what should happen here? The onAuthStateChanged
method emits either an AuthState
object or undefined
based on the user's login status. This is then combined with the query parameter called returnUrl
, which is always a string
.
Historically, the syntax used involved destructuring assignment signature ([authState, returnUrl])
, and as mentioned, it works fine in practice. It also doesn't throw errors on StackBlitz. But I'm facing issues in IntelliJ...
Could this be related to a breaking change in the latest RxJS version?
withLatestFrom
- Generic signatures have changed. Do not explicitly pass generics.
Source: https://rxjs.dev/6-to-7-change-summary#withlatestfrom
Even though it compiles and runs successfully. So, two questions:
- What is causing this error in IntelliJ?
- How can I resolve it? I've tried strongly typing all parameters without success...