Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
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
Explicitly setting return type
The difference is staggering