Tslint: no-void-expression does not support arrow function declaration

Created on 5 Apr 2018  路  3Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.8.1
  • __Running TSLint via__: CLI

TypeScript code being linted

window.setTimeout(() => alert(50), 0);

with tslint.json configuration:

{
    "rules": {
        "no-void-expression": true
    }
}

Actual behavior

no-void-expression because alert returns void.

Expected behavior

No error.

Duplicate Fixed

Most helpful comment

Finally have a solution!!! Add the following line in your tslint.json to allow arrow functions shorthand:

"no-void-expression": [true, "ignore-arrow-function-shorthand"],

All 3 comments

UPDATE: posting the solution in the following comment, you can ignore this...

I have a workaround but it does't solve the issue. When using a function that returns void:

.subscribe( something => someFunction(something));

no-voidexpression rule alerts that someFunction(something) returns void. Tried to type it but it keeps launching the error. The only workaround I found is to use curly brackets:

.subscribe( something => { someFunction(something); });

works fine, but i'd like to use it without the curly brackets.

Finally have a solution!!! Add the following line in your tslint.json to allow arrow functions shorthand:

"no-void-expression": [true, "ignore-arrow-function-shorthand"],

Yup! Duplicate of #2473.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajinder-yadav picture rajinder-yadav  路  3Comments

dashmug picture dashmug  路  3Comments

cateyes99 picture cateyes99  路  3Comments

avanderhoorn picture avanderhoorn  路  3Comments

ghost picture ghost  路  3Comments