Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it's possible to return an array in catchError() #7460

Closed
haexyh opened this issue Mar 28, 2024 · 2 comments
Closed

it's possible to return an array in catchError() #7460

haexyh opened this issue Mar 28, 2024 · 2 comments

Comments

@haexyh
Copy link

haexyh commented Mar 28, 2024

Describe the bug

I have discovered that it's possible to return an array in catchError.

Expected behavior

Returning arrays shouldn't be possible.
catchError(() => [])

Reproduction code

import { tap, switchMap, throwError, catchError, of } from "rxjs";
of(1)
  .pipe(
    tap(console.log),
    switchMap(() => throwError(() => new Error())),
    catchError(() => []),
  )
  .subscribe(console.log);

Reproduction URL

https://codesandbox.io/p/devbox/catcherror-issue-ld2pd7?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522cluaw6to000073b6lc47k8wmr%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522cluaw6to000023b6lvkv3v5ag%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522cluaw6to000043b6lqg5dww1y%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522cluaw6to000063b6lo6ueuwrr%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522cluaw6to000023b6lvkv3v5ag%2522%253A%257B%2522id%2522%253A%2522cluaw6to000023b6lvkv3v5ag%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522cluaw6to000063b6lo6ueuwrr%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluaw6to000053b6lq544m71b%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A5173%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522cluaw6to000063b6lo6ueuwrr%2522%252C%2522activeTabId%2522%253A%2522cluaw6to000053b6lq544m71b%2522%257D%252C%2522cluaw6to000043b6lqg5dww1y%2522%253A%257B%2522id%2522%253A%2522cluaw6to000043b6lqg5dww1y%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522cluaw6to000033b6lnuuh5tgl%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%255D%252C%2522activeTabId%2522%253A%2522cluaw6to000033b6lnuuh5tgl%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

Version

7.8.1

Environment

osx: 13.6.3 (22G436)

Additional context

No response

@haexyh
Copy link
Author

haexyh commented Mar 28, 2024

The issue can be closed, I recognize that this is a feature. An '[]' is ArrayLike

@jakovljevic-mladen
Copy link
Member

Indeed, it is a feature. It is designed to cover anything that can be converted to an Observable.

The interface for this operator is ObservableInput which includes ArrayLike - arrays can be converted to Observables.

Closing as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants