rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

[combineLatest] can not identify type of its params

Open lhbvita opened this issue 2 years ago • 1 comments

Describe the bug

here, this.__linkServ.links is type of Observable and this.__userServ.getUserInfo() is type of ReplaySubject<UserInfo>, but folow code get error. combineLatest([this.__linkServ.links, this.__userServ.getUserInfo()]) .pipe(takeUntil(this.__destroy$)) .subscribe(([links, userInfo]) => { const link = links?.tms_predefinedTag_common || ''; const hasAuth = !userInfo?.roles?.includes('op_gated_tms'); const predefinedTag = this.operators?.items?.[0]!; predefinedTag.hide = !(link && hasAuth); predefinedTag.link.href = link; });

image

if i specify the types manully like: combineLatest([this.__linkServ.links, this.__userServ.getUserInfo()] as [Observable<any>,Observable<any>]) .pipe(takeUntil(this.__destroy$)) .subscribe(([links, userInfo]) => { const link = links?.tms_predefinedTag_common || ''; const hasAuth = !userInfo?.roles?.includes('op_gated_tms'); const predefinedTag = this.operators?.items?.[0]!; predefinedTag.hide = !(link && hasAuth); predefinedTag.link.href = link; }); it is ok.

Another thing is, the former code combineLatest refers to image but the later refers to image

Expected behavior

no error

Reproduction code

No response

Reproduction URL

No response

Version

7.4.0

Environment

No response

Additional context

No response

lhbvita avatar Mar 08 '23 08:03 lhbvita

Can you please provide a playground with something that can be reproduced? Codesandbox or Stackblitz.

I tried a simple example

const links: Observable<unknown> = null as any;
const userInfo: ReplaySubject<unknown> = null as any;

combineLatest([links, userInfo]).subscribe(([links, userInfo]) => {
  // Works correctly
})

My env is [email protected]

If you manage to create a sandbox for it, it will be simpler to find out what's the issue

voliva avatar Mar 08 '23 09:03 voliva