You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because T bears no relation to ms, Wotan raises an error. However, our buffer function is required to return an OperatorFunction<T, R> which requires two type parameters and we need to provide them somehow. There is only one place we can declare T — the place it's defined here.
Despite the warning, this signature works as expected and T is inferred correctly.
Compliant implementation
We could make Wotan happy by inlining the definition instead of using OperatorFunction<T, R>.
The type parameter is defined next to the related argument, and everything works fine. Wotan is also happy. The problem is, we can't use the provided OperatorFunction<T, R> type anymore, so the implementation is not type-first anymore.
The big question: in such scenarios, should the programmer work around the warning by defining the function signature themselves, or should they be allowed to deliberately misplace the type parameter in order to feed the returned generic type that requires it?
I know it might be a case where disabling Wotan locally is justified (since the code works), but I wanted to bring that to your attention anyway. If handling such cases and making an exception for them is stupid or beyond the scope of this project, then please don't hesitate to close this issue.
Thank your for the detailed write-up. Unfortunately there's no way to detect this pattern.
The rule is only inspecting the declaration of your function signature without any knowledge about the intended (and actual) use. I don't see a possibility to exempt some functions from this rule based on syntax (or types).
I'm going to close this as it's not actionable.
As you already noted there are two possibilities: disable the rule for that particular line or work around the warning by using a more verbose syntax.
Hello and thank you for your wonderful tool.
As I was working with RxJS, the
no-misused-generics
rule highlighted an error saying my type parameter cannot be inferred from arguments.Example
We have an
Observable<string>
which is then piped using a custom operator, here calledbuffer
.The
pipe
method accepts functions of typeOperatorFunction<T, R>
.Non-compliant implementation
If we try and define
buffer
using theOperatorFunction
type provided byrxjs
, it looks like this:Because
T
bears no relation toms
, Wotan raises an error. However, ourbuffer
function is required to return anOperatorFunction<T, R>
which requires two type parameters and we need to provide them somehow. There is only one place we can declareT
— the place it's defined here.Despite the warning, this signature works as expected and
T
is inferred correctly.Compliant implementation
We could make Wotan happy by inlining the definition instead of using
OperatorFunction<T, R>
.The type parameter is defined next to the related argument, and everything works fine. Wotan is also happy. The problem is, we can't use the provided
OperatorFunction<T, R>
type anymore, so the implementation is not type-first anymore.The big question: in such scenarios, should the programmer work around the warning by defining the function signature themselves, or should they be allowed to deliberately misplace the type parameter in order to feed the returned generic type that requires it?
I know it might be a case where disabling Wotan locally is justified (since the code works), but I wanted to bring that to your attention anyway. If handling such cases and making an exception for them is stupid or beyond the scope of this project, then please don't hesitate to close this issue.
A complete snippet
I'm using
"rxjs": "^6.4.0"
.The text was updated successfully, but these errors were encountered: