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

multiple using of tap() causes a false error #7498

Open
its-dibo opened this issue Sep 11, 2024 · 1 comment
Open

multiple using of tap() causes a false error #7498

its-dibo opened this issue Sep 11, 2024 · 1 comment

Comments

@its-dibo
Copy link

its-dibo commented Sep 11, 2024

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

@martinsaison
Copy link

martinsaison commented Sep 13, 2024

According to the unit tests for pipe(), type should not be enforced beyond the 9th argument.
But the signature for pipe() with more than 9 arguments returns an Observable<unknown>. It should rather return a Observable<any> as the type safety of "unknown" can't be verified here at compilation time anyway.

In observable.ts:

 pipe<A, B, C, D, E, F, G, H, I>(
    op1: UnaryFunction<Observable<T>, A>,
    op2: UnaryFunction<A, B>,
    op3: UnaryFunction<B, C>,
    op4: UnaryFunction<C, D>,
    op5: UnaryFunction<D, E>,
    op6: UnaryFunction<E, F>,
    op7: UnaryFunction<F, G>,
    op8: UnaryFunction<G, H>,
    op9: UnaryFunction<H, I>,
    ...operations: OperatorFunction<any, any>[]
  ): Observable<any>; // <--- instead of Observable<unknown>

(* edited because markdown was removing my text between < > )

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