Skip to content

Unused Variables When Used As Typings #25

Closed
@JamesHenry

Description

@JamesHenry

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions