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

no-misused-generics: false negative #30

Closed
OliverJAsh opened this issue Apr 5, 2021 · 5 comments
Closed

no-misused-generics: false negative #30

OliverJAsh opened this issue Apr 5, 2021 · 5 comments
Labels
wontfix This will not be worked on

Comments

@OliverJAsh
Copy link

// Errors as expected
type MyFunction = <T>(param: T) => number;

// Expected error, got none
const myFunction = <T>(param: T) => 1;
@cartant
Copy link
Owner

cartant commented Apr 5, 2021

If you have TypeScript configured to parse JSX, the RHS of that variable declaration will be parsed as a JsxElement and will be ignored by the rule. Try:

const myFunction = <T,>(param: T) => 1;
//                   ^

@OliverJAsh
Copy link
Author

Unfortunately that doesn't seem to help. Reduced test case: https://github.com/OliverJAsh/eslint-no-misused-generics-test

@cartant
Copy link
Owner

cartant commented Apr 6, 2021

Not going to fix this 'cause I don't have the time to figure out why it's doing what it's doing:

// This test should fail, but it doesn't because the implementation tests
// the signature with:
//
// tsutils.isFunctionWithBody(signature)
//
// And if that returns true, the implementation assumes that the type
// parameter is used.
//
// fromFixture(stripIndent`
// // https://github.com/cartant/eslint-plugin-etc/issues/30
// const func = <T,>(param: T) => null;
// ~ [canReplace { "name": "T", "replacement": "unknown" }]
// `),

I didn't write this rule; I just ported it. And, TBH, I'm beginning to think that it's more trouble than it's worth. It's too simplistic and won't work with valid, but context-sensitive generic usage. I'm inclined to delete it and give the package a major version bump.

@cartant cartant added the wontfix This will not be worked on label Apr 6, 2021
@cartant
Copy link
Owner

cartant commented Apr 6, 2021

Thinking about it some more, my guess is that the original author made the (correct) decision that it's too difficult to determine whether what's returned relates to the parameter with the type parameter. E.g. this would be okay:

const myFunction = <T>(param: T) => param;

@OliverJAsh
Copy link
Author

You're totally right. I actually filed the same issue back when we were using Wotan 🤦. Sorry! fimbullinter/wotan#690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants