Tslint: Async function return void cause `invalid void`

Created on 21 Aug 2019  路  4Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.19.0
  • __TypeScript version__: 3.5.3
  • __Running TSLint via__: CLI / VSCode

    Reproduction using TSLint Playground

TypeScript code being linted

const sayHello = async (): Promise<void> => {
  // do something
}

with tslint.json configuration:

default

Actual behavior

After install [email protected], tslint reports it. In previous version tslint doesn't report this error.

tslint report

void is not a valid type other than return types (invalid-void)tslint(1)

Expected behavior

I think async function return Promise<void> is general usage. tslint shouldn't report the error.
invalid-void doc seems don't contain this usage.

Accepting PRs Rule Enhancement

Most helpful comment

Does allow-generics means whitelist for generics?

Yup!

why this problem only occurs in version 5.19.0. Is there any change in this rule? Thanks.

The invalid-void rule was added in 5.19.0: https://github.com/palantir/tslint/releases/tag/5.19.0. If you're using tslint:all to take in rules, this would have been enabled for you.

All 4 comments

Promise<void>

Sure, that seems like a common use case.

How about we add an option to the rule to allow generics to be void. It should allow either true for all generics or a string[] whitelist of allowed ones?

{
    "allow-generics": true
}
{
    "allow-generics": ["Promise"]
}

That's a good idea to solve this problem. So the invalid-void would be like this? Doesallow-generics means whitelist for generics?

{
  "invalid-void": {
      true;
     "allow-generics": true
  }
}

I have another question. why this problem only occurs in version 5.19.0. Is there any change in this rule? Thanks.

Does allow-generics means whitelist for generics?

Yup!

why this problem only occurs in version 5.19.0. Is there any change in this rule? Thanks.

The invalid-void rule was added in 5.19.0: https://github.com/palantir/tslint/releases/tag/5.19.0. If you're using tslint:all to take in rules, this would have been enabled for you.

Following, running into the same issue with return type of Promise<void>

Was this page helpful?
0 / 5 - 0 ratings