eslint / typescript-eslint-parser

An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Other
915 stars 92 forks source link

Unused Variables When Used As Typings #599

Closed nahtnam closed 5 years ago

nahtnam commented 5 years ago

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.

j-f1 commented 5 years ago

Do you have typescript/no-unused-vars enabled?

JamesHenry commented 5 years ago

This issue has been migrated to the new project here: typescript-eslint/typescript-eslint#25

Thanks!