Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Last active May 23, 2017 10:19
Show Gist options
  • Save amatiasq/7352f52d9290311589e3df5bc2afc1fe to your computer and use it in GitHub Desktop.
Save amatiasq/7352f52d9290311589e3df5bc2afc1fe to your computer and use it in GitHub Desktop.

Bug in TSLint no-unused-variable rule.

How to reproduce

If you run tslint -c tslint.json --type-check --project tsconfig.json '*.ts' in this folder you'll see:

$ tslint -c tslint.json --type-check --project tsconfig.json '*.ts'
ERROR: main.ts[1, 1]: All imports are unused.

Conditions

  • If you remove any of the files in this project (including fa.ts which is not used at all) the error disappears.
  • If you rename fa.ts to something after foo.ts (like h.ts, fz.ts or even fop.ts) the error disappears.
  • If you rename fa.ts to something before foo.ts (like a.ts or fon.ts) the error remains
  • If you empty fa.ts the error disappears
  • If you remove Foo import from main.ts and replace Foo<IBar> for Array<IBar> or Partial<IBar> the error disappears
  • And of course if your remove IBar import from main.ts and replace Foo<IBar> for Foo<{}> or something else the error disappears

TSLint version

5.2.0

Typescript version

2.3.2

Discussion

palantir/tslint#2577 (comment)

export interface IBar {
foo: boolean;
}
import { Foo } from "./foo";
// So we don't have "imports are not used" here
export { Foo };
export class Foo<T> {
public foo: T;
}
import { IBar } from "./bar";
import { Foo } from "./foo";
export function foo(bar: Foo<IBar>) {
return 1;
}
{
"extends": "tslint:recommended",
"rules": {
"no-unused-variable": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment