Skip to content

switchAll, mergeAll etc are not type safe #3841

@felixfbecker

Description

@felixfbecker

Bug Report

Current Behavior

const input: Observable<number> = of(1, 2, 3)
const output = input.pipe(switchAll())
output.subscribe(value => console.log(value))

No type error, but runtime error:

You provided '1' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Reproduction

Expected behavior
This should give a type error like number is not assignable to ObservableInput<T>

Environment

  • RxJS version: 6.2.1

Possible Solution
I tried a few things, but it seems like type inference just fails here. TypeScript needs to infer a type based on the usage of the return value here.

Workaround
Use switchMap(x => x) instead (switchMap(identity) also breaks inference)

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSIssues and PRs related purely to TypeScript issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions