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