Skip to content

Bug: [@typescript-eslint/no-invalid-void-type] void is only valid as a return type or generic type argument #6547

@splincode

Description

@splincode

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.3.2&fileType=.ts&code=FAQwRgzgLgTiDGUAE8A2IISQQUrBUAKgK4CWAIqSKgPYDmAygKYwBup8TAPANIB8SAN7AkSGgAcmAOy4BxJAF4krGqQAmfABQjRKGlKjSoALiQ8kTAB6GparCvVIA-EnmmeOgJTuL16XeVVNWdXJB9hXSQYJihiGCk9AyMAbh0AX2AM4CA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDcBDRgBNaPDpWFFS6MAG1w2HImjQO0SABp5CrAuyQB8DgHcAkkwDiiJkspkAKiUQBBaAHNYAWyv5UGfHEQtbABfIIBdeVDgoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

abstract class AbstractTuiDialogService<K> {
  open<G = void>(
    content: K extends void ? G : K
  ): K extends void ? G : K {
    return content;
  }
}

ESLint Config

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

tsconfig

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

Expected Result

error

Actual Result

No error for generic

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: 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