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

[explicit-function-return-type] Only apply to generic functions #730

Closed
Assignees
JoshuaKGoldberg
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@AnyhowStep

Description

@AnyhowStep

The template seems to be for bug reports but I have a feature request.

I would like a way to configureexplicit-function-return-type so that it only forces generic functions to have an explicit return type.

//Error, generic functions must have explicit return typefunctionfoo<TextendsSomeType>(t :T){return/*snip some code using `t`*/;}//OK! Not generic, so no need for explicit return typefunctionblah(t :SomeType){return/*snip some code using `t`*/;}

Rationale

In general,tsc's type inference is very fast.

However, when it comes to complicated generic types, type inference can fail and/or infer... unfavorable types. This is especially true of generic function return types.

I personally just had a check time performance issue that was fixed by adding an explicit return type annotation to one generic function.

It cut down check time byfive minutes


This missing one line of code caused me weeks of suffering =(

I do not wish for others and future me to trip over this again =(

In general, I tend to always add explicit retun types to all my generic functions. Theone time I forgot, it messed me up =(


Lettingtsc infer return type

image

Explicitly setting return type

image

The difference is staggering

Metadata

Metadata

Labels

accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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