Repository: palantir/tslint

Issue #2470: No unused variable for type alias and interface when used as generics.
Created: 2017-04-02T04:57:58Z
Bug Report

TSLint version: 5.0.0
TypeScript version: 2.2.2
Running TSLint via: CLI

TypeScript code being linted
describe('Action', () => {
    describe('actionCreator', () => {
        type DummyActionType = 'FOO' | 'BAR';

        interface Point {
            readonly x: number;
            readonly y: number;
        }

        it('creates the correct FSA for primitives', () => {
            const creator = actionCreator<DummyActionType, number>('FOO');
            creator(7).should.deep.equal({ type: 'FOO', payload: 7 });
        });

        it('creates the correct FSA for objects', () => {
            const creator = actionCreator<DummyActionType, Point>('BAR');
            creator({ x: 1, y: 3 }).should.deep.equal({
                type: 'BAR',
                payload: { x: 1, y: 3 },
            });
        });
    });
});
with tslint.json configuration:
{
    "defaultSeverity": "error",
    "extends": [
        // "tslint-microsoft-contrib",
        "tslint:recommended",
        "tslint-react"
    ],

    "rulesDirectory": [
        "./node_modules/tslint-immutable/rules"
    ],

    // additional rules aside from inherited ones
    "rules": {
        "arrow-parens": [true, "ban-single-arg-parens"],

        // possible errors (core TSLint)
        "no-switch-case-fall-through": true,
        "no-string-throw": true,

        // stylistic (core TSLint)
        "array-type": [true, "array"],
        "interface-name": [true, "never-prefix"],
        "no-null-keyword": true,
        "no-require-imports": true,
        "object-literal-sort-keys": false,
        "ordered-imports": [false], // array makes VSCode happy
        "quotemark": [true, "single", "jsx-double", "avoid-escape"],

        // best practices (core TSLint)
        "linebreak-style": [true, "LF"],
        "max-file-line-count": [true, 300],
        "max-line-length": [true, 100],
        "no-magic-numbers": true,
        "no-unused-expression": true,
        "no-unused-variable": [true, "check-parameters", "react"],
        "one-line": [false],
        "prefer-const": true,

        // functional programming
        "no-let": true, // no-var on by default
        "no-this": true,
        "no-class": true,
        "no-new": false, // records?
        "readonly-interface": true,
        "readonly-indexer": true,
        "readonly-array": true,
        "no-mixed-interface": true,

        // react
        "jsx-no-multiline-js": false,

        // legal
        "file-header": [true, "[+ ]{10,}"]
    }
}

Actual behavior
It marks the type alias and interface as unused.
src/frontend/actions/Action.test.ts
'DummyActionType' is declared but never used. (no-unused-variable)
  15 | describe('Action', () => {
  16 |     describe('actionCreator', () => {
> 17 |         type DummyActionType = 'FOO' | 'BAR';
     |             ^
  18 | 
  19 |         interface Point {
  20 |             readonly x: number;

'Point' is declared but never used. (no-unused-variable)
  17 |         type DummyActionType = 'FOO' | 'BAR';
  18 | 
> 19 |         interface Point {
     |                  ^
  20 |             readonly x: number;
  21 |             readonly y: number;
  22 |         }


Expected behavior
The type alias and interface are used as generic arguments, and should have no lint errors.

Duplicate issue #2621: Regression: no-unused-variable misbehaving for generic types
Created: 2017-04-21T01:01:38Z
Bug Report

TSLint version: 5.1.0
TypeScript version: 2.2.2
Running TSLint via: CLI

TypeScript code being linted
type Props = {
    foo: string,
};

export class X extends React.Component<Props, void> {}
with tslint.json configuration:
{
    "extends": "tslint:latest",
    "defaultSeverity": "error",
    "rules": {
        "interface-over-type-literal": false,
        "no-unused-variable": true
    }
}
seet gist here for a full example: https://gist.github.com/joscha/6633bae73fb4b143cfb685b2754259c9
run yarn install && yarn test to see the regression.
Actual behavior
yarn test v0.23.2
$ tslint  --type-check --project tsconfig.json index.ts

ERROR: index.ts[3, 6]: 'Props' is declared but never used.
error Command failed with exit code 2.

Expected behavior
Props is used in the type definition of the React component. This worked with TSLint 4.x.

Closing comment (2017-04-21T01:47:03Z): I think this is the same as #2470. There was a breaking change in v5.0 where we switched to using tsc's implementation of "no unused variable".