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

no-unused-variable interferes with other type checked rules #2736

Closed
CSchulz opened this issue May 11, 2017 · 4 comments
Closed

no-unused-variable interferes with other type checked rules #2736

CSchulz opened this issue May 11, 2017 · 4 comments

Comments

@CSchulz
Copy link
Contributor

CSchulz commented May 11, 2017

Bug Report

  • TSLint version: 5.2.0 / 5.4.3
  • TypeScript version: 2.3.1
  • Running TSLint via: (pick one) CLI / Node.js API / VSCode / grunt-tslint / Atom / Visual Studio / etc

TypeScript code being linted

https://github.com/CSchulz/tslint-type-check-rule-collision

  protected createDefaultLogMessage(msg: LogMessage): string {
    const format: LogFormat = msg.logGroupRule.logFormat;
    let result: string = '';
    if (format.showTimeStamp) {
      result += MessageFormatUtils.renderDate(msg.date, format.dateFormat) + ' ';
    }

with tslint.json configuration:

"restrict-plus-operands": true,
"no-unused-variable": true

Actual behavior

app/app.component.ts[30, 17]: Operands of '+' operation must either be both strings or both numbers
app/app.component.ts[33, 15]: Operands of '+' operation must either be both strings or both numbers
app/app.component.ts[38, 15]: Operands of '+' operation must either be both strings or both numbers
app/app.component.ts[40, 17]: Operands of '+' operation must either be both strings or both numbers

Expected behavior

Nothing should violate.

If you disable the rule no-unused-variable it works fine.

@CSchulz CSchulz changed the title type-check rules collides with external library type-check rules collide with external library May 11, 2017
@andy-hanson
Copy link
Contributor

no-unused-variable may be exposing some bugs within TypeScript; see #2649.
(You could always just set "no-unused-locals" and "no-unused-parameters" in your config instead of using the lint rule.)

@CSchulz
Copy link
Contributor Author

CSchulz commented Jun 12, 2017

My reproducer is still broken with tslint 5.4.

A workaround is the usage of type assertion:

  protected createDefaultLogMessage(msg: LogMessage): string {
    const format: LogFormat = msg.logGroupRule.logFormat;
    let result: string = '';
    if (format.showTimeStamp) {
      result += <string>MessageFormatUtils.renderDate(msg.date, format.dateFormat) + ' ';
    }

@ajafff ajafff changed the title type-check rules collide with external library no-unused-variable interferes with other type checked rules Nov 5, 2017
@jscharett
Copy link

Any plans on fixing this?

@JoshuaKGoldberg
Copy link
Contributor

I can no longer get this to reproduce with TypeScript 3.1.3 and TSLint 5.11. Hilarious bug, likely aged away.

Closing for housekeeping purposes, but please do post more source code & versions if it pops up again!

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

5 participants