8000 Bug: [@typescript-eslint/no-invalid-void-type] false positive on generics · Issue #7227 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
Bug: [@typescript-eslint/no-invalid-void-type] false positive on generics #7227
Closed as not planned
@G-Rath

Description

@G-Rath

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.1.6&fileType=.tsx&code=CYUwxgNghgTiAEAzArgOzAFwJYHtXwFsAPAHgBUA%2BACgEoAueMgbgFgAod4kgNxy2Go1WHNhBwBzAIKpgAJRAZkMVDz4CqaUIiyoQwIe3YQF8XvwAKMHASwBnEA0vW7IVfwrwAvPF0B3eE429m7qtF4eAN7wAL4GoiZmwACyUAAODCmpJLYYMDriADSmah7efvCZ2bn5RYmCTEA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDcBDRgBNaPDpWFFS6KImjQO0SODABfECqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare function mx<T>(): T;

mx<void>();

logAndReturn<void>(undefined);

let voidPromise: Promise<void> = new Promise<void>(() => { });
let voidMap: Map<string, void> = new Map<string, void>();

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-invalid-void-type": "error"
  },
};

tsconfig

{

6565
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expected all of these to be considered valid uses of void

Actual Result

Only the last two uses are considered valid.

Additional Info

Maybe I'm missing something but I've read the docs a couple of times and the issues, and I can't find anything explaining why this general use of void is being flagged - or inversely, anything confirming that there is more logic than just "is this a generic?".

Importantly the logAndReturn is taken from the documentation itself for showcasing

The following patterns are considered warnings with { allowInGenericTypeArguments: false }:

Which implies to me those patterns should not be considered warnings if allowInGenericTypeArguments is true. This seems to be happening from v5 onwards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedbugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0