-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Improve documentation for typescript/no-unused-vars
#46
Comments
typescript/no-unused-vars
only supports decoratorstypescript/no-unused-vars
@JamesHenry We can close this issue now 😃 |
Actually I don't think we can? My PR added this rule to the list, but it doesn't add more detail as per this issue. |
@JamesHenry can we consider removing this rule in favor of TypeScript own flags --noUnusedParameters and --noUnusedLocals?. I think this rule is causing a lot of confusion and giving a lot of false/positives. |
I think that TypeScript did not include |
I appreciate having a |
This is a very good point. I will continue working on this rule for as long as it's needed. |
What is the correct setting for this rule? If I'm understanding correctly, it should prevent ESLint from erroneously throwing these errors, but I can't for the life of me to get it to work and since it's not operating as a rule so much as a workaround it's not clear to me what value I should set it to. |
Hi @tenshiemi, this rule extends eslint/no-unused-vars to include TypeScript syntax. You will need both defined in your eslint config to make it work. What I usually do is extend the eslint:recommended settings, then manually enable typescript/no-unused-vars Hope this helps. |
@weirdpattern Thanks, this is what I have both it throws a bunch of no-unused-vars and no-undef warnings:
|
@tenshiemi, we are still working on this rule, we keep finding scenarios that we missed and have to be included. |
@weirdpattern I just realized it works when I run an example is |
Here's a scenario where it fails: import { FieldRenderProps } from 'react-final-form'
const Error = ({ meta }: { meta: FieldRenderProps['meta'] }) => null |
Instead of creating a new issue, I'll just report some more findings.
import { Foo } from './types';
class Bar<T extends Foo> {}
import webpack from 'webpack';
export default function webpackLoader(this: webpack.loader.LoaderContext) {}
import execa, { Options as ExecaOptions } from 'execa';
function foo(options: ExecaOptions) {}
import { Foo, Bar } from './types';
class Baz<Foo & Bar> {} |
As of the latest commit (5e410a36c43d82ab679bed8a8ef68a655008fde9), I'm seeing this snippet pass as a local import { FieldRenderProps } from 'react-final-form'
const Error = ({ meta }: { meta: FieldRenderProps['meta'] }) => null I've confirmed the following as a failing test and will open a PR to address what I believe is the issue: import { Foo } from './types';
class Bar<T extends Foo> {} I'm not able to reproduce "'ExecaOptions' is defined by never used" in the following snippet. I see the following errors locally. @milesj do you have a reproducible test case of this issue, perhaps by adding a failing test in a PR? That would be awesome 😄 import execa, { Options as ExecaOptions } from 'execa';
function foo(options: ExecaOptions) {}
|
@macklinu Here's the execa full code: https://github.com/milesj/boost/blob/master/src/Routine.ts#L111 It's probably the wrapping parens + union causing it. |
Think I found a few more. import { Foo, Bar } from './types';
// Doesnt catch either mapped types
const NAMES: { [name in Foo]: Bar } = {}; |
@milesj pushed up 9f0caf3 in #135 to address https://github.com/nzakas/eslint-plugin-typescript/issues/33#issuecomment-400063994. |
Any update on this? If you're open to assigning collaborators, I could help go through some of these issues/PRs. |
// warning 'B' is defined but never used
const a: Array<{b: B}> = [] |
Another false positive: declare type Checker = (v) => v is number;
const checker: Checker = (w): w is number => true; Here |
Also, since this lint seems to be mostly covered by the Typescript option, maybe it's a good idea to remove it from |
@ThomasdenH - please raise that error as a separate issue. There is discussion about no-unused-vars in the recommended set in #122. Considering we're working on improving this constantly, I'm going to close this issue. |
@bradzacher Does your last comment mean that the issue regarding Cause it causes frustation to have to disable the My, minimal reproduction is import { IOptions } from './types'
const options: IOptions = {}
... // Use `options` later resulting in
Where should we follow the status on this ? We should have a unclosed issue pending until it's not fixed. After more than 1 hour figuring what's going on with the severals issues refering to |
@kevinmarrec - which issue? There are a number of edge cases that aren't properly covered by the rule. Some we know about, many we don't. This issue is specifically about attempting to document the cases that are currently unsupported, but it has accidentally gone off the rails and become a place people are putting bug reports. A growing thread which has a mixture between discussions, bug reports and examples is not a good way to document issues with the rule. One issue opened per bug, on the other hand, clearly documents what problems are known and open with the rule. It's very hard to track which bugs are fixed if they are all logged as comments in a single thread: a thread isn't easily searchable, we can't close comments once their issue is fixed, and we can't clearly link to comments in PRs. This the primary reason I've closed this issue. Please open a new issue if you find a case that's not properly covered by the rule so that we can properly track the bug. |
Alright @bradzacher, I understand. The issue is that Well for my specific case I ended up with this workaround
which seems to fit my use case, but I think it should work without having to do this workaround. If I find some time, I'll open an issue with minimal reproduction through a repository. |
Thank you @kevinmarrec! It's working fine, now. |
@kevinmarrec Thank you! |
- occur `no-unused-vars` error and change eslint rule - typescript-eslint/typescript-eslint#46 (comment)
@bradzacher : I had the same problem. The solution which @kevinmarrec provided worked for me as well. using 2.6.1 version of the plugin. |
There are several use cases
typescript/no-unused-vars
does not yet support, such astype
declarations:Would it be possible to track the status of this somewhere in the documentation? The docs for
typescript/no-unused-vars
do not make any mention of this.I would be happy to raise a PR, but I don't know the full details of what is and isn't supported.
The text was updated successfully, but these errors were encountered: