Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-unused-variable: false positive for exported function return type #1157

Closed
msklvsk opened this issue Apr 22, 2016 · 2 comments
Closed

no-unused-variable: false positive for exported function return type #1157

msklvsk opened this issue Apr 22, 2016 · 2 comments

Comments

@msklvsk
Copy link

msklvsk commented Apr 22, 2016

Bug Report

  • TSLint version: 3.8.0
  • TypeScript version: 1.8.10
  • Running TSLint via: gulp-tslint

TypeScript code being linted

import {Server, createServer} from 'http';
// unused variable: 'Server' (while it is used as return type)

export function getServer() {
  return createServer();
}

with tslint.json:

{
  "rules": {
    "no-unused-variable": true
  }
}

Actual behavior

An error unused variable: 'Server' is reported, but it is used as a return type and removing Server from imports causes a native typescript error: Return type of exported function has or is using name 'Server' from external module "http" but cannot be named

Expected behavior

no tslint error is reported

@adidahiya
Copy link
Contributor

Hm, this is an interesting problem with implicit typedefs that hasn't really come up before. Not sure if we'll be able to identify Server as an implicitly-used type, especially without full type checker info (#680). For now I would suggest adding an explicit return type to getServer (IMO it's good practice to do so for exported APIs anyway).

@andy-hanson
Copy link
Contributor

This is handled in #2235. Although it should be fixed in TypeScript itself, for which the issue is microsoft/TypeScript#9944 or microsoft/TypeScript#13694.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants