-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
"no-misused-generics" warns about code that seems correct? #24
Comments
This is a port of a Wotan rule - the link is in the docs if you want to see if there are any similar issue in its repo. I can have more of a think about this tomorrow. I'm curious, though: does it still effect a failure if the |
There are zero errors when Args is inlined like this: interface MyFunction {
<Foo>(args: { foo: Foo; fooKey: keyof Foo }): any;
} Yep, I looked through Wotan repository, found this which seemed similar: fimbullinter/wotan#663 |
Yeah, that's fine. I was just wondering whether there is a fundamental problem with the rule.
AFAICT, that means the rule could also fail if the type parameter is placed on the interface and not on the signature. The Wotan issue looks like the issue that Dan opened in this repo. This is a little different. There might be a way to make this work. I'll have a think about it. |
For the moment, I've removed |
I'm still standing by my idea of adding an option to ignore this rule when a non-inferred T is passed as a type parameter into some other generic type. But it's still up to you! |
I'm not sure if there's a bug indeed or if I'm just wrong here.
Code:
Explanation:
Foo
is used to enforce a constraint betweenfoo: Foo
andfooKey: keyof Foo
.You can see how the constraint allows for type-safety in the last two lines of my example.
I can only pass keys of
foo
in thefooKey
parameter.But
no-misused-generics
thinks that is redundant. When I replace<Foo>(args: Args<Foo>): any;
with(args: Args<any>): any;
or(args: Args<unknown>): any;
my code stops working as intended.Possible fix:
Ignore this rule when a type parameter is used as a nested type parameter in another generic type. If somewhere down the line this type is indeed not used to enforce a constraint, then we'll see this error down the line.
The text was updated successfully, but these errors were encountered: