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

Unused Variables When Used As Typings #25

Closed
JamesHenry opened this issue Jan 15, 2019 · 5 comments · Fixed by #68
Closed

Unused Variables When Used As Typings #25

JamesHenry opened this issue Jan 15, 2019 · 5 comments · Fixed by #68
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JamesHenry
Copy link
Member

This issue was initially reported here: eslint/typescript-eslint-parser#599


I'm still new to TypeScript so apologizes if I misunderstood this issue.

What version of TypeScript are you using?
3.2.2

What version of typescript-eslint-parser are you using?
21.0.2

What code were you trying to parse?

import * as fastify from 'fastify'
import { Server, IncomingMessage, ServerResponse } from 'http'

// Create a http server. We pass the relevant typings for our http version used.
// By passing types we get correctly typed access to the underlying http objects in routes.
// If using http2 we'd pass <http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse>
const server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse> = fastify({})

const opts: fastify.RouteShorthandOptions = {
  schema: {
    response: {
      200: {
        type: 'object',
        properties: {
          pong: {
            type: 'string'
          }
        }
      }
    }
  }
}

server.get('/ping', opts, (request, reply) => {
  console.log(reply.res) // this is the http.ServerResponse with correct typings!
  reply.code(200).send({ pong: 'it worked!' })
})

From: https://github.com/fastify/fastify/blob/master/docs/TypeScript.md#example

What did you expect to happen?
No errors relating unused variables.

What happened?
It complains that Server, IncomingMessage, ServerResponse are all unused but technically they are used when defining the server variable.

@JamesHenry JamesHenry added the package: parser Issues related to @typescript-eslint/parser label Jan 18, 2019
@bradzacher bradzacher added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look migration-test and removed package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Jan 18, 2019
@Chris911
Copy link

@JamesHenry I'm still getting this issue with v1.1.1 @typescript-eslint/no-unused-vars errors variable imported as types and only used for typing.

@armano2
Copy link
Member

armano2 commented Jan 29, 2019

can you provide example of code?

no-unused-vars.js#L522

@Chris911
Copy link

Here's a simple repo setup to reproduce: https://gist.github.com/Chris911/69305fa1697683b90f578e9d9244fdec

In the example MongooseTypes is imported and then used in another interface but eslint errors on L1.

@armano2
Copy link
Member

armano2 commented Jan 29, 2019

yes, that's true, this is different issue #21,
declare global uses "global" scope

@Chris911
Copy link

Ah ok. Thanks I'll follow that issue.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants