@@ -151,17 +151,41 @@ module TypeResolution {
151151 )
152152 }
153153
154+ bindingset [ name]
155+ private predicate isPromiseTypeName ( string name ) {
156+ name .regexpMatch ( ".?(Promise|Thenable)(Like)?" )
157+ }
158+
159+ private Node unwrapPromiseType ( Node promiseType ) {
160+ exists ( GenericTypeExpr type |
161+ promiseType = type and
162+ isPromiseTypeName ( type .getTypeAccess ( ) .( LocalTypeAccess ) .getName ( ) ) and
163+ result = type .getTypeArgument ( 0 )
164+ )
165+ or
166+ exists ( JSDocAppliedTypeExpr type |
167+ promiseType = type and
168+ isPromiseTypeName ( type .getHead ( ) .( JSDocLocalTypeAccess ) .getName ( ) ) and
169+ result = type .getArgument ( 0 )
170+ )
171+ }
172+
154173 private predicate contextualType ( Node value , Node type ) {
155174 exists ( InvokeExpr call , Function target , int i |
156175 callTarget ( call , target ) and
157176 value = call .getArgument ( i ) and
158177 type = target .getParameter ( i ) .getTypeAnnotation ( )
159178 )
160179 or
161- exists ( Function lambda |
162- not lambda .isAsyncOrGenerator ( ) and
180+ exists ( Function lambda , Node returnType |
163181 value = lambda .getAReturnedExpr ( ) and
164- functionReturnType ( lambda , type )
182+ functionReturnType ( lambda , returnType )
183+ |
184+ not lambda .isAsyncOrGenerator ( ) and
185+ type = returnType
186+ or
187+ lambda .isAsync ( ) and
188+ type = unwrapPromiseType ( returnType )
165189 )
166190 or
167191 exists ( ObjectExpr object , Node objectType , Node host , string name |
0 commit comments