fix: use "unknown" type for operators that ignore input values #6738
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Description:
After upgrading an application's typescript-eslint dependency from 4.30 to 5.9, I found that the "@typescript-eslint/no-unsafe-argument" rule was flagging my use of the RxJS
mapTo
andignoreElements
operators, because they return functions that operate on observables ofany
. Since the operator functions ignore the values from the source observable, they don't need the dynamic typing thatany
provides for accessing the values. Usingunknown
instead makes it clear (to both eslint and humans) that the operator function doesn't have any expectations about the type of observable it's given.This PR changes
OperatorFunction<any, ...>
toOperatorFunction<unknown, ...>
in the return type ofignoreElements
and themapTo
family of operators. No implementation changes are needed in the functions, since the associated values are never used anyway. This shouldn't be a breaking change:unknown
is the same asany
from a caller's perspective (no restrictions on what can be passed in), andOperatorFunction<unknown, ...>
is assignable toOperatorFunction<any, ...>
so anything that explicitly expects the latter is still OK.