-
-
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
False positive for no-misused-generics #15
Comments
I'm not convinced that this is a bug or a false positive. Rather, I think this is one of the exceptions to the rule. As with operators and If const b = both((name: string) => {}, (age: number) => {}); // (...args: unknown[]) => void IMO, this is an example of a situation in which the rule is inappropriate and I don't see how the rule could cope with these situations - given that the declaration and the call sites are separated, so to speak. Thoughts? |
One option could be a specific failure message that states that inference is only possible via the return value. |
That's a good point @cartant. The error would have to be at the call site, not the definition. Or perhaps this is just a case where disabling the linter for that line makes sense. |
Yes, I'm running into this a lot with operators. Not just for RxJS but all the types in fp-ts. Reduced test case: const fn = <E>() => (e: E): E => e; Maybe this lint rule should only be concerned with the definition, not the call site (we could have a separate lint rule for that). In that case, this lint rule would determine this is a safe definition, because the generic is used in two positions: a parameter and the return type. |
@OliverJAsh ATM, I have little appetite for tweaking this rule, as I didn't write it; I just ported it. I've removed it from the recommended configuration, as I think there are too many exceptions and I don't want to support/explain them. In the example, |
3+ years later, I see that my export function both<Args extends unknown[]>(
fn1: (...args: Args) => void,
fn2: (...args: Args) => void,
): (...args: Args) => void {
return function (...args: Args) {
fn1(...args);
fn2(...args);
};
} Maybe TypeScript has gotten smarter since 2020? Or maybe this was just working as intended all along! |
Here's a generic function:
I think this is fine in terms of every type parameter appearing multiple times.
Args
only appears in otherextends
clauses, but it can still be inferred. Here's an example of it being used, with all the parameters inferred:Mousing over
both
in that example, I see:In other words,
Args
is very much inferred.The text was updated successfully, but these errors were encountered: