Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-invalid-void-type] Intersection with never should be allowed #1946

Closed
jens-duttke opened this issue Apr 28, 2020 · 3 comments · Fixed by #1960
Closed

[no-invalid-void-type] Intersection with never should be allowed #1946

jens-duttke opened this issue Apr 28, 2020 · 3 comments · Fixed by #1960
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@jens-duttke
Copy link
Contributor

Repro

{
  "rules": {
    "@typescript-eslint/no-invalid-void-type": "error"
  }
}
function foo (): void | never {
    throw new Error('Test');
}

Expected Result

That the no-invalid-void-type does not complain about the void | never union.

Actual Result

void is only valid as a return type or generic type variable [Error/@typescript-eslint/no-invalid-void-type]

Versions

package version
@typescript-eslint/eslint-plugin 2.30.0
@typescript-eslint/parser 2.30.0
TypeScript 3.9.0-dev.20200419
ESLint 6.8.0
node 13.6.0
npm 6.14.4
@jens-duttke jens-duttke added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 28, 2020
@bradzacher
Copy link
Member

How come you're using void | never?
TypeScript collapses the never out of the return type, so it's like it's never even there.

Is it purely for documentation that the function may throw?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Apr 28, 2020
@jens-duttke
Copy link
Contributor Author

@bradzacher: Yes, right now it's purely for documentation. But I also have the hope that some day, either TypeScript or an ESLint plugin does something useful with it. ;-)

@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed awaiting response Issues waiting for a reply from the OP or another party labels May 4, 2020
@sinyovercosy
Copy link
Contributor

This should be an easy fix once #1960 is merged - all that should be needed is to add never as a valid member type to the isValidUnionType function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants