ReactiveX/rxjs

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

haexyh opened this issue · 2 comments

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

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

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.