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

Rule proposal: disallow unused return types #6442

Open
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@KhafraDev

Description

@KhafraDev

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Paired withexplicit-function-return-types, it's possible to include extraneous return types that are never used. This can happen when refactoring code meaning that some code branches might become impossible to reach.

For example you might have this function:

functionrandom(param?:string):string|null{if(typeofparam!=='string')returnnullreturn'has param'}

where the return types are correct, but then it's refactored to

// note that param is no longer optional but the return type is the same unionfunctionrandom(param:string):string|null{return'has param'}

and let's assume it's being used in a codebase before param is required:

constrand=random(param)if(rand===null){thrownewError('...')}

since the return type is unchanged, the null check branch might not be removed during refactoring, and neither the linter or tsc will complain about it.

Fail Cases

functiontest():string|null{return'string'}classA{statictest():string|null{return'string'}test():string|null{return'string'}}

Pass Cases

functiontest():string{return'string'}classA{statictest():string|null{if(Math.random()<0.5)returnnullreturn'string'}test():string{return'string'}}

Additional Info

It's totally possible I missed an issue that matched this proposal, but I couldn't find any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp