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-unused-vars] false positive for imported types #1542

Closed
StrangeWill opened this issue Jan 29, 2020 · 2 comments
Closed

[no-unused-vars] false positive for imported types #1542

StrangeWill opened this issue Jan 29, 2020 · 2 comments
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser

Comments

@StrangeWill
Copy link

Repro

<script lang="ts">
// ...
import { AxiosError } from "axios";
// ...

const response = await this.$http
	.post<JwtToken>(
		"authentication_token",
		{
			email: this.username,
			password: this.password
		},
		{
			headers: {
				authorization: ""
			}
		}
	)
	.catch((error: AxiosError) => { // <-- this line right here
		if (error?.response?.status == 401) {
			throw "Login Failed";
		}

		throw error?.message;
	});
// ...

Expected Result

Should pass es-lint fine

Actual Result

It sometimes passes es-lint, appears to do it on first pass, but fails on subsequent passes when running npm run serve.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.18.0
@typescript-eslint/parser 2.18.0
TypeScript 3.7.5
ESLint 6.8.0
node 12.14.1
npm 6.13.6
@StrangeWill StrangeWill added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 29, 2020
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser and removed triage Waiting for maintainers to take a look labels Jan 29, 2020
@bradzacher bradzacher changed the title [no-unused-vars] False Positive "AxiosError is defined but never used [no-unused-vars] false positive for imported types Mar 4, 2020
@abraham
Copy link

abraham commented Apr 2, 2020

Since TypeScript 2.9 you can work around this with import types.

.catch((error: import("axios").AxiosError) => {

@bradzacher bradzacher added this to the scope analysis rewrite milestone Apr 6, 2020
@bradzacher
Copy link
Member

Merging into #1856

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser
Projects
None yet
Development

No branches or pull requests

3 participants