ReactiveX / ReactiveX/rxjs

multiple using of tap() causes a false error

Open
#7,498 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

the following code is correct, but will generate a false error

import { Observable, of, tap } from 'rxjs';

let test$: Observable<number> = of(1).pipe(
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
  tap(() => 1),
);

Error:

Type 'Observable<unknown>' is not assignable to type 'Observable<number>'.
  Type 'unknown' is not assignable to type 'number'.ts(2322)

commenting any of tap() blocks causes the error to be disappeared.

also, explicitly set the type again resolves the error. but TS can infer the type easily

of(1).pipe( ... ) as Observable<number>
Expected behavior

no error

Reproduction code

No response

Reproduction URL

https://stackblitz.com/edit/rxjs-jvajmd?devtoolsheight=60&file=index.ts,tsconfig.json

Version

next

Environment

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproduction, especially index.ts and tsconfig.json, and reduce the example to repeated tap() calls while checking the inferred type. Done means the shown Observable assignment compiles without an explicit type assertion and the false error no longer appears.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.