@@ -79,7 +79,9 @@ import {
79
79
isTypeOmitted ,
80
80
FunctionExpression ,
81
81
NewExpression ,
82
- ArrayLiteralExpression
82
+ ArrayLiteralExpression ,
83
+ ArrowKind ,
84
+ ExpressionStatement
83
85
} from "./ast" ;
84
86
85
87
import {
@@ -2613,7 +2615,25 @@ export class Resolver extends DiagnosticEmitter {
2613
2615
/** How to proceed with eventual diagnostics. */
2614
2616
reportMode : ReportMode = ReportMode . REPORT
2615
2617
) : Type | null {
2616
- return this . resolveFunctionType ( node . declaration . signature , ctxFlow . actualFunction , ctxFlow . contextualTypeArguments , reportMode ) ;
2618
+ const declaration = node . declaration ;
2619
+ const signature = declaration . signature ;
2620
+ const body = declaration . body ;
2621
+ let functionType = this . resolveFunctionType ( signature , ctxFlow . actualFunction , ctxFlow . contextualTypeArguments , reportMode ) ;
2622
+ if (
2623
+ functionType &&
2624
+ declaration . arrowKind != ArrowKind . NONE &&
2625
+ body && body . kind == NodeKind . EXPRESSION &&
2626
+ isTypeOmitted ( signature . returnType )
2627
+ ) {
2628
+ // (x) => ret, infer return type accordingt to `ret`
2629
+ const expr = ( < ExpressionStatement > body ) . expression ;
2630
+ const type = this . resolveExpression ( expr , ctxFlow , ctxType , ReportMode . SWALLOW ) ;
2631
+ if ( type ) {
2632
+ let signatureReference = assert ( functionType . getSignature ( ) ) ;
2633
+ signatureReference . returnType = type ;
2634
+ }
2635
+ }
2636
+ return functionType ;
2617
2637
}
2618
2638
2619
2639
// ==================================================== Elements =====================================================
0 commit comments