Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [no-invalid-void-type] Can't usevoid in return type union for overloaded function #5752

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@haines

Description

@haines

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 havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.4&sourceType=module&code=GYVwdgxgLglg9mABMAFASgFyIG5xgEwG4AoUSWBZFADywGcoAnGMAc00QebZLOniSpqAfnpMW7LLgKIAPp3FtEAb2KJEMYIhqIAhAF59icPgCmwFqfxoVa9YkamoIRkmol1AX2LfS4fpSs6FgACoxwALYwdKYAPNL4AHy8-hRIQbQK3JKIYZHRcVwSycQAhnQAnpDIqQKIGaJZEhx5UTHxePhyTWyJtuqa2tR6hsZgZhZgVjaq9g5OLm4eiN6eQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1uYDcBDRgBNaPDpWFFS6KImjQO0SODABfECqA&tsconfig=N4XyA

Repro Code

functionf():void;functionf(x:string):string;functionf(x?:string):void|string{if(x!==undefined){returnx;}}functiong():Promise<void>;functiong(x:string):Promise<string>;asyncfunctiong(x?:string):Promise<void|string>{if(x!==undefined){returnx;}}

ESLint Config

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

tsconfig

{}

Expected Result

No errors.

Actual Result

void is only valid as a return type or generic type variable. 3:25 - 3:29
void is only valid as a return type or generic type variable. 11:39 - 11:43

Additional Info

It's possible to work around the linter in the first example by changing the implementation return type fromvoid | ... toundefined | ..., although this may require introducing an explicitreturn undefined statement to the function body if the compiler optionnoImplicitReturns is set.

In the second example, changingPromise<void | ...> toPromise<undefined | ...> is not possible because it introduces a compiler error

This overload signature is not compatible with its implementation signature. (2394)

Versions

packageversion
@typescript-eslint/eslint-plugin5.39.0
@typescript-eslint/parser5.39.0
TypeScript4.8.4
ESLint8.15.0
nodeweb

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp