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

Async function return void cause invalid void #4828

Closed
ruowan opened this issue Aug 21, 2019 · 4 comments · Fixed by #4839
Closed

Async function return void cause invalid void #4828

ruowan opened this issue Aug 21, 2019 · 4 comments · Fixed by #4839

Comments

@ruowan
Copy link

ruowan commented Aug 21, 2019

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 tslint@5.19.0, 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.

@JoshuaKGoldberg
Copy link
Contributor

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"]
}

@ruowan
Copy link
Author

ruowan commented Aug 21, 2019

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.

@JoshuaKGoldberg
Copy link
Contributor

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.

@michaelw85
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants