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

After upgrade to 7.2.0 mapTo(true) violates and shows @typescript-eslint/no-unsafe-argument error #6536

vitalyiegorov opened this issue Jul 26, 2021 · 6 comments


Copy link

@vitalyiegorov vitalyiegorov commented Jul 26, 2021

Bug Report

We have migrated our codebase from 6.6.6 to 7.2.0 and have a an issue for mapTo(true) operator from eslint:

ESLint: Unsafe argument of type `OperatorFunction<any, boolean>` assigned to a parameter of type `OperatorFunction<DeleteResult, boolean>`.(@typescript-eslint/no-unsafe-argument)

Investigating the sources:

export function mapTo<R>(value: R): OperatorFunction<any, R>;
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
export function mapTo<T, R>(value: R): OperatorFunction<T, R>;

Current Behavior
ESLint error is shown, without providing generics for mapTo operator.

Expected behavior
No ESLint errors, without additional generics for mapTo operator.




  • Runtime: Node v16.1.0
  • RxJS version: 7.2.0

Possible Solution
Seems like the problem is with any, changing the type to use generics, fixes the issue, and you can use it in your code without specifying them:

export declare function mapTo<T, R>(value: R): OperatorFunction<T, R>;
Copy link

@cartant cartant commented Jul 28, 2021

T serves no purpose in the signature - as mentioned in the deprecation comment - and it would be incorrect to use it. (The general rule is that a type parameter should be used more than once in a signature.)

any could - indeed should - be replaced with unknown. Replacing the uses of any - throughout the API - with unknown is some that will be (eventually) be done.

Copy link

@benlesh benlesh commented Aug 9, 2021

@cartant are we tracking the change for any to unknown anywhere? It seems like that's a version 8 thing. (Also we can probably close this)

@benlesh benlesh closed this as completed Aug 9, 2021
Copy link

@cartant cartant commented Aug 9, 2021


... are we tracking the change for any to unknown anywhere?

Added it to #6367

Copy link

@rassie rassie commented Dec 10, 2021

So what is the solution here, why is this closed? No matter which signature I'd use, I'll get an ESlint warning, either for deprecation or for unsafe arguments.

Copy link

@manbearwiz manbearwiz commented Dec 29, 2021

Its clunky, but you can use a type assertion to specify the return type as unknown instead of any until they handle it internally. This removes the error for me. Replace



switchMapTo(this.service.isAlive()) as OperatorFunction<unknown, boolean>

Copy link

@benlesh benlesh commented Jan 5, 2022

Does map(() => true) work for you? (That's all that mapTo does internally)

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

No branches or pull requests

5 participants